/* * SM4 key schedule (128-bit, decryption) */ void sm4_setkey_dec( sm4_context *ctx, unsigned char key[16] ) { int i; ctx->mode = SM4_ENCRYPT; sm4_setkey( ctx->sk, key ); for( i = 0; i < 16; i ++ ) { SWAP( ctx->sk[ i ], ctx->sk[ 31-i] ); } }
int main(void) { sm4_ctx c; //uint32_t i; int equ; sm4_setkey(&c, tv_key, SM4_ENCRYPT); //for (i=0; i<1000000; i++) { sm4_encrypt(&c, tv_plain); //} equ = memcmp(tv_cipher, tv_plain, 16)==0; printf ("SM4 Test %s\n", equ ? "succeeded" : "failed"); return 0; }
/* * SM4 key schedule (128-bit, encryption) */ void sm4_setkey_enc( sm4_context *ctx, unsigned char key[16] ) { ctx->mode = SM4_ENCRYPT; sm4_setkey( ctx->sk, key ); }