Skip to content

Commit

Permalink
XTS use new GF(2^128) API
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed Apr 11, 2024
1 parent f9e9b20 commit e4502dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/sm4_xts.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ int sm4_xts_encrypt(const SM4_KEY *key1, const SM4_KEY *key2, const uint8_t twea
sm4_encrypt(key1, block, block);
gmssl_memxor(out, block, T, 16);

a = gf128_from_bytes(T);
a = gf128_mul2(a);
gf128_from_bytes(a, T);
gf128_mul_by_2(a, a);
gf128_to_bytes(a, T);

in += 16;
Expand All @@ -55,8 +55,8 @@ int sm4_xts_encrypt(const SM4_KEY *key1, const SM4_KEY *key2, const uint8_t twea
sm4_encrypt(key1, block, block);
gmssl_memxor(block, block, T, 16);

a = gf128_from_bytes(T);
a = gf128_mul2(a);
gf128_from_bytes(a, T);
gf128_mul_by_2(a, a);
gf128_to_bytes(a, T);

in += 16;
Expand Down Expand Up @@ -95,8 +95,8 @@ int sm4_xts_decrypt(const SM4_KEY *key1, const SM4_KEY *key2, const uint8_t twea
sm4_decrypt(key1, block, block);
gmssl_memxor(out, block, T, 16);

a = gf128_from_bytes(T);
a = gf128_mul2(a);
gf128_from_bytes(a, T);
gf128_mul_by_2(a, a);
gf128_to_bytes(a, T);

in += 16;
Expand All @@ -112,8 +112,8 @@ int sm4_xts_decrypt(const SM4_KEY *key1, const SM4_KEY *key2, const uint8_t twea
} else {
uint8_t T1[16];

a = gf128_from_bytes(T);
a = gf128_mul2(a);
gf128_from_bytes(a, T);
gf128_mul_by_2(a, a);
gf128_to_bytes(a, T1);

gmssl_memxor(block, in, T1, 16);
Expand Down
4 changes: 2 additions & 2 deletions tools/sm4.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ int sm4_main(int argc, char **argv)
goto end;
}

#ifdef ENABLE_SM4_XTS
if (mode == SM4_MODE_XTS) {
#ifdef ENABLE_SM4_CCM
if (mode == SM4_MODE_CCM) {
if (sm4_ccm_crypt(key, keylen, iv, ivlen, aad, aadlen, taglen, infp, outfp, enc, prog) != 1) {
goto end;
}
Expand Down

0 comments on commit e4502dd

Please sign in to comment.