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>
This commit is contained in:
@ -458,7 +458,7 @@ void FAST_FUNC md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len)
|
||||
* endian byte order, so that a byte-wise output yields to the wanted
|
||||
* ASCII representation of the message digest.
|
||||
*/
|
||||
void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf)
|
||||
unsigned FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf)
|
||||
{
|
||||
/* MD5 stores total in LE, need to swap on BE arches: */
|
||||
common64_end(ctx, /*swap_needed:*/ BB_BIG_ENDIAN);
|
||||
@ -472,6 +472,7 @@ void FAST_FUNC md5_end(md5_ctx_t *ctx, void *resbuf)
|
||||
}
|
||||
|
||||
memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * 4);
|
||||
return sizeof(ctx->hash[0]) * 4;
|
||||
}
|
||||
|
||||
|
||||
@ -865,7 +866,7 @@ void FAST_FUNC sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len)
|
||||
#endif /* NEED_SHA512 */
|
||||
|
||||
/* Used also for sha256 */
|
||||
void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf)
|
||||
unsigned FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf)
|
||||
{
|
||||
unsigned hash_size;
|
||||
|
||||
@ -879,11 +880,13 @@ void FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf)
|
||||
for (i = 0; i < hash_size; ++i)
|
||||
ctx->hash[i] = SWAP_BE32(ctx->hash[i]);
|
||||
}
|
||||
memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * hash_size);
|
||||
hash_size *= sizeof(ctx->hash[0]);
|
||||
memcpy(resbuf, ctx->hash, hash_size);
|
||||
return hash_size;
|
||||
}
|
||||
|
||||
#if NEED_SHA512
|
||||
void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf)
|
||||
unsigned FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf)
|
||||
{
|
||||
unsigned bufpos = ctx->total64[0] & 127;
|
||||
|
||||
@ -915,6 +918,7 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf)
|
||||
ctx->hash[i] = SWAP_BE64(ctx->hash[i]);
|
||||
}
|
||||
memcpy(resbuf, ctx->hash, sizeof(ctx->hash));
|
||||
return sizeof(ctx->hash);
|
||||
}
|
||||
#endif /* NEED_SHA512 */
|
||||
|
||||
@ -1450,7 +1454,7 @@ void FAST_FUNC sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len)
|
||||
#endif
|
||||
}
|
||||
|
||||
void FAST_FUNC sha3_end(sha3_ctx_t *ctx, void *resbuf)
|
||||
unsigned FAST_FUNC sha3_end(sha3_ctx_t *ctx, void *resbuf)
|
||||
{
|
||||
/* Padding */
|
||||
uint8_t *buf = (uint8_t*)ctx->state;
|
||||
@ -1475,4 +1479,5 @@ void FAST_FUNC sha3_end(sha3_ctx_t *ctx, void *resbuf)
|
||||
|
||||
/* Output */
|
||||
memcpy(resbuf, ctx->state, 64);
|
||||
return 64;
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ void FAST_FUNC md5_hash(const void *buffer, size_t inputLen, md5_ctx_t *context)
|
||||
* MD5 finalization. Ends an MD5 message-digest operation,
|
||||
* writing the message digest.
|
||||
*/
|
||||
void FAST_FUNC md5_end(void *digest, md5_ctx_t *context)
|
||||
unsigned FAST_FUNC md5_end(void *digest, md5_ctx_t *context)
|
||||
{
|
||||
unsigned idx, padLen;
|
||||
unsigned char bits[8];
|
||||
@ -457,4 +457,5 @@ void FAST_FUNC md5_end(void *digest, md5_ctx_t *context)
|
||||
|
||||
/* Store state in digest */
|
||||
memcpy32_cpu2le(digest, context->state, 16);
|
||||
return 16;
|
||||
}
|
||||
|
@ -18,9 +18,10 @@ static char *
|
||||
NOINLINE
|
||||
sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
|
||||
{
|
||||
#undef sha_end
|
||||
void (*sha_begin)(void *ctx) FAST_FUNC;
|
||||
void (*sha_hash)(void *ctx, const void *buffer, size_t len) FAST_FUNC;
|
||||
void (*sha_end)(void *ctx, void *resbuf) FAST_FUNC;
|
||||
unsigned (*sha_end)(void *ctx, void *resbuf) FAST_FUNC;
|
||||
int _32or64;
|
||||
|
||||
char *result, *resptr;
|
||||
|
Reference in New Issue
Block a user