Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: streebog - Use API partial block handling

Use the Crypto API partial block handling.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+25 -51
+25 -46
crypto/streebog_generic.c
··· 13 13 */ 14 14 15 15 #include <crypto/internal/hash.h> 16 - #include <linux/module.h> 17 - #include <linux/crypto.h> 18 16 #include <crypto/streebog.h> 17 + #include <linux/kernel.h> 18 + #include <linux/module.h> 19 + #include <linux/string.h> 19 20 20 21 static const struct streebog_uint512 buffer0 = { { 21 22 0, 0, 0, 0, 0, 0, 0, 0 ··· 920 919 return 0; 921 920 } 922 921 923 - static void streebog_pad(struct streebog_state *ctx) 924 - { 925 - if (ctx->fillsize >= STREEBOG_BLOCK_SIZE) 926 - return; 927 - 928 - memset(ctx->buffer + ctx->fillsize, 0, 929 - sizeof(ctx->buffer) - ctx->fillsize); 930 - 931 - ctx->buffer[ctx->fillsize] = 1; 932 - } 933 - 934 922 static void streebog_add512(const struct streebog_uint512 *x, 935 923 const struct streebog_uint512 *y, 936 924 struct streebog_uint512 *r) ··· 974 984 streebog_add512(&ctx->Sigma, &m, &ctx->Sigma); 975 985 } 976 986 977 - static void streebog_stage3(struct streebog_state *ctx) 987 + static void streebog_stage3(struct streebog_state *ctx, const u8 *src, 988 + unsigned int len) 978 989 { 979 990 struct streebog_uint512 buf = { { 0 } }; 991 + union { 992 + u8 buffer[STREEBOG_BLOCK_SIZE]; 993 + struct streebog_uint512 m; 994 + } u = {}; 980 995 981 - buf.qword[0] = cpu_to_le64(ctx->fillsize << 3); 982 - streebog_pad(ctx); 996 + buf.qword[0] = cpu_to_le64(len << 3); 997 + memcpy(u.buffer, src, len); 998 + u.buffer[len] = 1; 983 999 984 - streebog_g(&ctx->h, &ctx->N, &ctx->m); 1000 + streebog_g(&ctx->h, &ctx->N, &u.m); 985 1001 streebog_add512(&ctx->N, &buf, &ctx->N); 986 - streebog_add512(&ctx->Sigma, &ctx->m, &ctx->Sigma); 1002 + streebog_add512(&ctx->Sigma, &u.m, &ctx->Sigma); 1003 + memzero_explicit(&u, sizeof(u)); 987 1004 streebog_g(&ctx->h, &buffer0, &ctx->N); 988 1005 streebog_g(&ctx->h, &buffer0, &ctx->Sigma); 989 1006 memcpy(&ctx->hash, &ctx->h, sizeof(struct streebog_uint512)); ··· 1000 1003 unsigned int len) 1001 1004 { 1002 1005 struct streebog_state *ctx = shash_desc_ctx(desc); 1003 - size_t chunksize; 1004 1006 1005 - if (ctx->fillsize) { 1006 - chunksize = STREEBOG_BLOCK_SIZE - ctx->fillsize; 1007 - if (chunksize > len) 1008 - chunksize = len; 1009 - memcpy(&ctx->buffer[ctx->fillsize], data, chunksize); 1010 - ctx->fillsize += chunksize; 1011 - len -= chunksize; 1012 - data += chunksize; 1013 - 1014 - if (ctx->fillsize == STREEBOG_BLOCK_SIZE) { 1015 - streebog_stage2(ctx, ctx->buffer); 1016 - ctx->fillsize = 0; 1017 - } 1018 - } 1019 - 1020 - while (len >= STREEBOG_BLOCK_SIZE) { 1007 + do { 1021 1008 streebog_stage2(ctx, data); 1022 1009 data += STREEBOG_BLOCK_SIZE; 1023 1010 len -= STREEBOG_BLOCK_SIZE; 1024 - } 1011 + } while (len >= STREEBOG_BLOCK_SIZE); 1025 1012 1026 - if (len) { 1027 - memcpy(&ctx->buffer, data, len); 1028 - ctx->fillsize = len; 1029 - } 1030 - return 0; 1013 + return len; 1031 1014 } 1032 1015 1033 - static int streebog_final(struct shash_desc *desc, u8 *digest) 1016 + static int streebog_finup(struct shash_desc *desc, const u8 *src, 1017 + unsigned int len, u8 *digest) 1034 1018 { 1035 1019 struct streebog_state *ctx = shash_desc_ctx(desc); 1036 1020 1037 - streebog_stage3(ctx); 1038 - ctx->fillsize = 0; 1021 + streebog_stage3(ctx, src, len); 1039 1022 if (crypto_shash_digestsize(desc->tfm) == STREEBOG256_DIGEST_SIZE) 1040 1023 memcpy(digest, &ctx->hash.qword[4], STREEBOG256_DIGEST_SIZE); 1041 1024 else ··· 1027 1050 .digestsize = STREEBOG256_DIGEST_SIZE, 1028 1051 .init = streebog_init, 1029 1052 .update = streebog_update, 1030 - .final = streebog_final, 1053 + .finup = streebog_finup, 1031 1054 .descsize = sizeof(struct streebog_state), 1032 1055 .base = { 1033 1056 .cra_name = "streebog256", 1034 1057 .cra_driver_name = "streebog256-generic", 1058 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 1035 1059 .cra_blocksize = STREEBOG_BLOCK_SIZE, 1036 1060 .cra_module = THIS_MODULE, 1037 1061 }, ··· 1040 1062 .digestsize = STREEBOG512_DIGEST_SIZE, 1041 1063 .init = streebog_init, 1042 1064 .update = streebog_update, 1043 - .final = streebog_final, 1065 + .finup = streebog_finup, 1044 1066 .descsize = sizeof(struct streebog_state), 1045 1067 .base = { 1046 1068 .cra_name = "streebog512", 1047 1069 .cra_driver_name = "streebog512-generic", 1070 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 1048 1071 .cra_blocksize = STREEBOG_BLOCK_SIZE, 1049 1072 .cra_module = THIS_MODULE, 1050 1073 }
-5
include/crypto/streebog.h
··· 23 23 }; 24 24 25 25 struct streebog_state { 26 - union { 27 - u8 buffer[STREEBOG_BLOCK_SIZE]; 28 - struct streebog_uint512 m; 29 - }; 30 26 struct streebog_uint512 hash; 31 27 struct streebog_uint512 h; 32 28 struct streebog_uint512 N; 33 29 struct streebog_uint512 Sigma; 34 - size_t fillsize; 35 30 }; 36 31 37 32 #endif /* !_CRYPTO_STREEBOG_H_ */