des.h des.c 怎么用?

LENOVO_ 2011-10-18 09:38:06
我搞到了 des 算法源代码。

是下面这一份:


des.h

#ifndef _DES_H
#define _DES_H

#ifndef uint8
#define uint8 unsigned char
#endif

#ifndef uint32
#define uint32 unsigned long int
#endif

typedef struct
{
uint32 esk[32]; /* DES encryption subkeys */
uint32 dsk[32]; /* DES decryption subkeys */
} des_context;

typedef struct
{
uint32 esk[96]; /* Triple-DES encryption subkeys */
uint32 dsk[96]; /* Triple-DES decryption subkeys */
} des3_context;

int des_set_key( des_context *ctx, uint8 key[8] );
void des_encrypt( des_context *ctx, uint8 input[8], uint8 output[8] );
void des_decrypt( des_context *ctx, uint8 input[8], uint8 output[8] );

int des3_set_2keys( des3_context *ctx, uint8 key1[8], uint8 key2[8] );
int des3_set_3keys( des3_context *ctx, uint8 key1[8], uint8 key2[8], uint8 key3[8] );

void des3_encrypt( des3_context *ctx, uint8 input[8], uint8 output[8] );
void des3_decrypt( des3_context *ctx, uint8 input[8], uint8 output[8] );

#endif /* des.h */



des.c

/*
* FIPS-46-3 compliant 3DES implementation
*
* Copyright (C) 2001-2003 Christophe Devine
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/



但是 不知道怎么用,要按什么顺序调用哪几个函数。

知道的能帮忙说一下吗?

我只要3DES加密解密。
...全文
422 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
LENOVO_ 2011-10-18
  • 打赏
  • 举报
回复
已经搞好了。

先 弄3 个8字节的数组,利用 des3_set_3keys 得到 des3_context

再 把 要加密的数据整成8的倍数的长度。

最后 调用 des3_encrypt 从尾部加密8个字节的数组,每8个字节一组,直到头部。

解密过程就是反过来的。
LENOVO_ 2011-10-18
  • 打赏
  • 举报
回复
一个 数组进过 3DES加密后,长度应该不会变吧?
LENOVO_ 2011-10-18
  • 打赏
  • 举报
回复
void des3_encrypt( des3_context *ctx, uint8 input[8], uint8 output[8] );

后2 个参数 是 8字节的数组。

对于一个 长度大于8字节的 内容。 要 循环吧

会不会搞?
  • 打赏
  • 举报
回复
看名字应该是


des_set_key

des_encrypt 或des_decrypt

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧