From acba64a9e0e420e44d789217a982438fa0fbb593 Mon Sep 17 00:00:00 2001 From: jsing Date: Thu, 28 Mar 2024 08:37:03 +0000 Subject: [PATCH] Expand ROTATE macro to crypto_rol_u32(). --- lib/libcrypto/sm3/sm3.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/libcrypto/sm3/sm3.c b/lib/libcrypto/sm3/sm3.c index 2b3a8e37282..d3c7c5b2ea0 100644 --- a/lib/libcrypto/sm3/sm3.c +++ b/lib/libcrypto/sm3/sm3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sm3.c,v 1.13 2024/03/28 08:33:14 jsing Exp $ */ +/* $OpenBSD: sm3.c,v 1.14 2024/03/28 08:37:03 jsing Exp $ */ /* * Copyright (c) 2018, Ribose Inc * @@ -21,6 +21,8 @@ #include +#include "crypto_internal.h" + #ifndef OPENSSL_NO_SM3 #define DATA_ORDER_IS_BIG_ENDIAN @@ -42,8 +44,8 @@ void SM3_transform(SM3_CTX *c, const unsigned char *data); #include "md32_common.h" -#define P0(X) (X ^ ROTATE(X, 9) ^ ROTATE(X, 17)) -#define P1(X) (X ^ ROTATE(X, 15) ^ ROTATE(X, 23)) +#define P0(X) (X ^ crypto_rol_u32(X, 9) ^ crypto_rol_u32(X, 17)) +#define P1(X) (X ^ crypto_rol_u32(X, 15) ^ crypto_rol_u32(X, 23)) #define FF0(X, Y, Z) (X ^ Y ^ Z) #define GG0(X, Y, Z) (X ^ Y ^ Z) @@ -52,17 +54,17 @@ void SM3_transform(SM3_CTX *c, const unsigned char *data); #define GG1(X, Y, Z) ((Z ^ (X & (Y ^ Z)))) #define EXPAND(W0, W7, W13, W3, W10) \ - (P1(W0 ^ W7 ^ ROTATE(W13, 15)) ^ ROTATE(W3, 7) ^ W10) + (P1(W0 ^ W7 ^ crypto_rol_u32(W13, 15)) ^ crypto_rol_u32(W3, 7) ^ W10) #define ROUND(A, B, C, D, E, F, G, H, TJ, Wi, Wj, FF, GG) do { \ - const SM3_WORD A12 = ROTATE(A, 12); \ + const SM3_WORD A12 = crypto_rol_u32(A, 12); \ const SM3_WORD A12_SM = A12 + E + TJ; \ - const SM3_WORD SS1 = ROTATE(A12_SM, 7); \ + const SM3_WORD SS1 = crypto_rol_u32(A12_SM, 7); \ const SM3_WORD TT1 = FF(A, B, C) + D + (SS1 ^ A12) + (Wj); \ const SM3_WORD TT2 = GG(E, F, G) + H + SS1 + Wi; \ - B = ROTATE(B, 9); \ + B = crypto_rol_u32(B, 9); \ D = TT1; \ - F = ROTATE(F, 19); \ + F = crypto_rol_u32(F, 19); \ H = P0(TT2); \ } while(0) -- 2.20.1