aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-24 16:00:54 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-24 16:00:54 +0100
commit49ecee098d062b92fcf095e05e15779c32899646 (patch)
treea02df1cfc23064d3f37a7adb15e1dafdf7a76c97 /libbb
parent9a64c3337cc0a5e84e9ad457eeb1d475c311e9fc (diff)
downloadbusybox-w32-49ecee098d062b92fcf095e05e15779c32899646.tar.gz
busybox-w32-49ecee098d062b92fcf095e05e15779c32899646.tar.bz2
busybox-w32-49ecee098d062b92fcf095e05e15779c32899646.zip
tls: add 2nd cipher_id, TLS_RSA_WITH_AES_128_CBC_SHA, so far it doesn't work
Good news that TLS_RSA_WITH_AES_256_CBC_SHA256 still works with new code ;) This change adds inevitable extension to have different sized hashes and AES key sizes. In libbb, md5_end() and shaX_end() are extended to return result size instead of void - this helps *a lot* in tls (the cost is ~5 bytes per _end() function). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/hash_md5_sha.c15
-rw-r--r--libbb/hash_md5prime.c3
-rw-r--r--libbb/pw_encrypt_sha.c3
3 files changed, 14 insertions, 7 deletions
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
index d325584d7..2a7247430 100644
--- a/libbb/hash_md5_sha.c
+++ b/libbb/hash_md5_sha.c
@@ -458,7 +458,7 @@ void FAST_FUNC md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len)
458 * endian byte order, so that a byte-wise output yields to the wanted 458 * endian byte order, so that a byte-wise output yields to the wanted
459 * ASCII representation of the message digest. 459 * ASCII representation of the message digest.
460 */ 460 */
461void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf) 461unsigned FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf)
462{ 462{
463 /* MD5 stores total in LE, need to swap on BE arches: */ 463 /* MD5 stores total in LE, need to swap on BE arches: */
464 common64_end(ctx, /*swap_needed:*/ BB_BIG_ENDIAN); 464 common64_end(ctx, /*swap_needed:*/ BB_BIG_ENDIAN);
@@ -472,6 +472,7 @@ void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf)
472 } 472 }
473 473
474 memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * 4); 474 memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * 4);
475 return sizeof(ctx->hash[0]) * 4;
475} 476}
476 477
477 478
@@ -865,7 +866,7 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len)
865#endif /* NEED_SHA512 */ 866#endif /* NEED_SHA512 */
866 867
867/* Used also for sha256 */ 868/* Used also for sha256 */
868void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf) 869unsigned FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf)
869{ 870{
870 unsigned hash_size; 871 unsigned hash_size;
871 872
@@ -879,11 +880,13 @@ void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf)
879 for (i = 0; i < hash_size; ++i) 880 for (i = 0; i < hash_size; ++i)
880 ctx->hash[i] = SWAP_BE32(ctx->hash[i]); 881 ctx->hash[i] = SWAP_BE32(ctx->hash[i]);
881 } 882 }
882 memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * hash_size); 883 hash_size *= sizeof(ctx->hash[0]);
884 memcpy(resbuf, ctx->hash, hash_size);
885 return hash_size;
883} 886}
884 887
885#if NEED_SHA512 888#if NEED_SHA512
886void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf) 889unsigned FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf)
887{ 890{
888 unsigned bufpos = ctx->total64[0] & 127; 891 unsigned bufpos = ctx->total64[0] & 127;
889 892
@@ -915,6 +918,7 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf)
915 ctx->hash[i] = SWAP_BE64(ctx->hash[i]); 918 ctx->hash[i] = SWAP_BE64(ctx->hash[i]);
916 } 919 }
917 memcpy(resbuf, ctx->hash, sizeof(ctx->hash)); 920 memcpy(resbuf, ctx->hash, sizeof(ctx->hash));
921 return sizeof(ctx->hash);
918} 922}
919#endif /* NEED_SHA512 */ 923#endif /* NEED_SHA512 */
920 924
@@ -1450,7 +1454,7 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len)
1450#endif 1454#endif
1451} 1455}
1452 1456
1453void FAST_FUNC sha3_end(sha3_ctx_t *ctx, void *resbuf) 1457unsigned FAST_FUNC sha3_end(sha3_ctx_t *ctx, void *resbuf)
1454{ 1458{
1455 /* Padding */ 1459 /* Padding */
1456 uint8_t *buf = (uint8_t*)ctx->state; 1460 uint8_t *buf = (uint8_t*)ctx->state;
@@ -1475,4 +1479,5 @@ void FAST_FUNC sha3_end(sha3_ctx_t *ctx, void *resbuf)
1475 1479
1476 /* Output */ 1480 /* Output */
1477 memcpy(resbuf, ctx->state, 64); 1481 memcpy(resbuf, ctx->state, 64);
1482 return 64;
1478} 1483}
diff --git a/libbb/hash_md5prime.c b/libbb/hash_md5prime.c
index e089a15f5..4b58d37ff 100644
--- a/libbb/hash_md5prime.c
+++ b/libbb/hash_md5prime.c
@@ -437,7 +437,7 @@ void FAST_FUNC md5_hash(const void *buffer, size_t inputLen, md5_ctx_t *context)
437 * MD5 finalization. Ends an MD5 message-digest operation, 437 * MD5 finalization. Ends an MD5 message-digest operation,
438 * writing the message digest. 438 * writing the message digest.
439 */ 439 */
440void FAST_FUNC md5_end(void *digest, md5_ctx_t *context) 440unsigned FAST_FUNC md5_end(void *digest, md5_ctx_t *context)
441{ 441{
442 unsigned idx, padLen; 442 unsigned idx, padLen;
443 unsigned char bits[8]; 443 unsigned char bits[8];
@@ -457,4 +457,5 @@ void FAST_FUNC md5_end(void *digest, md5_ctx_t *context)
457 457
458 /* Store state in digest */ 458 /* Store state in digest */
459 memcpy32_cpu2le(digest, context->state, 16); 459 memcpy32_cpu2le(digest, context->state, 16);
460 return 16;
460} 461}
diff --git a/libbb/pw_encrypt_sha.c b/libbb/pw_encrypt_sha.c
index 72e37e485..5457d7ab6 100644
--- a/libbb/pw_encrypt_sha.c
+++ b/libbb/pw_encrypt_sha.c
@@ -18,9 +18,10 @@ static char *
18NOINLINE 18NOINLINE
19sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data) 19sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
20{ 20{
21#undef sha_end
21 void (*sha_begin)(void *ctx) FAST_FUNC; 22 void (*sha_begin)(void *ctx) FAST_FUNC;
22 void (*sha_hash)(void *ctx, const void *buffer, size_t len) FAST_FUNC; 23 void (*sha_hash)(void *ctx, const void *buffer, size_t len) FAST_FUNC;
23 void (*sha_end)(void *ctx, void *resbuf) FAST_FUNC; 24 unsigned (*sha_end)(void *ctx, void *resbuf) FAST_FUNC;
24 int _32or64; 25 int _32or64;
25 26
26 char *result, *resptr; 27 char *result, *resptr;