资源简介
sm2sm3sm4各中语言版本的实现,包括java、c、javascript、python四个语言版本,有需要的可以下载(java版的只有一个SM4的例子; javascript版的有SM2、SM3、SM4,)
代码片段和文件信息
/*
* SM4 Encryption alogrithm (SMS4 algorithm)
* GM/T 0002-2012 Chinese National Standard ref:http://www.oscca.gov.cn/
* thanks to Xyssl
* thnaks and refers to http://hi.baidu.com/numax/blog/item/80addfefddfb93e4cf1b3e61.html
* author:goldboar
* email:goldboar@163.com
* 2012-4-20
*/
#define SM4_ENCRYPT 1
#define SM4_DECRYPT 0
/**
* \brief SM4 context structure
*/
typedef struct
{
int mode; /*!< encrypt/decrypt */
unsigned long sk[32]; /*!< SM4 subkeys */
}
sm4_context;
/**
* \brief SM4 key schedule (128-bit encryption)
*
* \param ctx SM4 context to be initialized
* \param key 16-byte secret key
*/
void sm4_setkey_enc( sm4_context *ctx unsigned char key[16] );
/**
* \brief SM4 key schedule (128-bit decryption)
*
* \param ctx SM4 context to be initialized
* \param key 16-byte secret key
*/
void sm4_setkey_dec( sm4_context *ctx unsigned char key[16] );
/**
* \brief SM4-ECB block encryption/decryption
* \param ctx SM4 context
* \param mode SM4_ENCRYPT or SM4_DECRYPT
* \param length length of the input data
* \param input input block
* \param output output block
*/
void sm4_crypt_ecb( sm4_context *ctx
int mode
int length
unsigned char *input
unsigned char *output);
/**
* \brief SM4-CBC buffer encryption/decryption
* \param ctx SM4 context
* \param mode SM4_ENCRYPT or SM4_DECRYPT
* \param length length of the input data
* \param iv initialization vector (updated after use)
* \param input buffer holding the input data
* \param output buffer holding the output data
*/
void sm4_crypt_cbc( sm4_context *ctx
int mode
int length
unsigned char iv[16]
unsigned char *input
unsigned char *output );
// Test vector 1
// plain: 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
// key: 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
// round key and temp computing result:
// rk[ 0] = f12186f9 X[ 0] = 27fad345
// rk[ 1] = 41662b61 X[ 1] = a18b4cb2
// rk[ 2] = 5a6ab19a X[ 2] = 11c1e22a
// rk[ 3] = 7ba92077 X[ 3] = cc13e2ee
// rk[ 4] = 367360f4 X[ 4] = f87c5bd5
// rk[ 5] = 776a0c61 X[ 5] = 33220757
// rk[ 6] = b6bb89b3 X[ 6] = 77f4c297
// rk[ 7] = 24763151 X[ 7] = 7a96f2eb
// rk[ 8] = a520307c X[ 8] = 27dac07f
// rk[ 9] = b7584dbd X[ 9] = 42dd0f19
// rk[10] = c30753ed X[10] = b8a5da02
// rk[11] = 7ee55b57 X[11] = 907127fa
// rk[12] = 6988608c X[12] = 8b952b83
// rk[13] = 30d895b7 X[13] = d42b7c59
// rk[14] = 44ba14af X[14] = 2ffc5831
// rk[15] = 104495a1 X[15] = f69e6888
// rk[16] = d120b428 X[16] = af2432c4
// rk[17] = 73b55fa3 X[17] = ed1ec85e
// rk[18] = cc874966 X[18] = 55a3ba2
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-11-15 07:30 sm4-master\
目录 0 2017-11-15 07:30 sm4-master\C\
目录 0 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\
目录 0 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\
文件 1301 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\kdf.h
目录 0 2018-08-07 17:49 __MACOSX\
目录 0 2018-08-07 17:49 __MACOSX\sm4-master\
目录 0 2018-08-07 17:49 __MACOSX\sm4-master\C\
目录 0 2018-08-07 17:49 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\
目录 0 2018-08-07 17:49 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\._kdf.h
文件 18385 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\sm2.c
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\._sm2.c
文件 3445 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\sm2.dsp
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\._sm2.dsp
文件 500 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\sm2.dsw
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\._sm2.dsw
文件 884 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\sm2.h
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\._sm2.h
文件 13124 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\sm2test.c
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM2\._sm2test.c
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\._SM2
目录 0 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\
文件 10157 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\sm3.c
目录 0 2018-08-07 17:49 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\._sm3.c
文件 2897 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\sm3.h
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\._sm3.h
文件 802 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\sm3test.c
文件 222 2017-11-15 07:30 __MACOSX\sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\._sm3test.c
文件 3483 2017-11-15 07:30 sm4-master\C\SM2_SM3_SM4_C璇█瀹炵幇\SM3\sm3test.dsp
............此处省略220个文件信息
评论
共有 条评论