mirror of https://github.com/ARMmbed/mbed-os.git
Remove last code redundancy
parent
53027fd590
commit
88c3b3ee28
|
@ -127,42 +127,40 @@ void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_
|
||||||
void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
|
void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
|
||||||
{
|
{
|
||||||
size_t currentlen = ilen;
|
size_t currentlen = ilen;
|
||||||
if (st_md5_restore_hw_context(ctx) != 1) {
|
/* If ilen = 0 : do nothing */
|
||||||
return; // Return HASH_BUSY timout error here
|
if (currentlen != 0) {
|
||||||
}
|
if (st_md5_restore_hw_context(ctx) != 1) {
|
||||||
// store mechanism to accumulate ST_MD5_BLOCK_SIZE bytes (512 bits) in the HW
|
return; // Return HASH_BUSY timout error here
|
||||||
if (currentlen == 0){ // only change HW status is size if 0
|
|
||||||
if(ctx->hhash_md5.Phase == HAL_HASH_PHASE_READY) {
|
|
||||||
/* Select the MD5 mode and reset the HASH processor core, so that the HASH will be ready to compute
|
|
||||||
the message digest of a new message */
|
|
||||||
HASH->CR |= HASH_ALGOSELECTION_MD5 | HASH_CR_INIT;
|
|
||||||
}
|
}
|
||||||
ctx->hhash_md5.Phase = HAL_HASH_PHASE_PROCESS;
|
|
||||||
} else if (currentlen < (ST_MD5_BLOCK_SIZE - ctx->sbuf_len)) {
|
// store mechanism to accumulate ST_MD5_BLOCK_SIZE bytes (512 bits) in the HW
|
||||||
// only buffurize
|
if (currentlen < (ST_MD5_BLOCK_SIZE - ctx->sbuf_len)) {
|
||||||
memcpy(ctx->sbuf+ctx->sbuf_len, input, currentlen);
|
// only buffurize
|
||||||
ctx->sbuf_len += currentlen;
|
memcpy(ctx->sbuf+ctx->sbuf_len, input, currentlen);
|
||||||
} else {
|
ctx->sbuf_len += currentlen;
|
||||||
// fill buffer and process it
|
} else {
|
||||||
memcpy(ctx->sbuf + ctx->sbuf_len, input, (ST_MD5_BLOCK_SIZE - ctx->sbuf_len));
|
// fill buffer and process it
|
||||||
currentlen -= (ST_MD5_BLOCK_SIZE - ctx->sbuf_len);
|
memcpy(ctx->sbuf + ctx->sbuf_len, input, (ST_MD5_BLOCK_SIZE - ctx->sbuf_len));
|
||||||
mbedtls_md5_process(ctx, ctx->sbuf);
|
currentlen -= (ST_MD5_BLOCK_SIZE - ctx->sbuf_len);
|
||||||
// Process every input as long as it is %64 bytes, ie 512 bits
|
mbedtls_md5_process(ctx, ctx->sbuf);
|
||||||
size_t iter = currentlen / ST_MD5_BLOCK_SIZE;
|
// Process every input as long as it is %64 bytes, ie 512 bits
|
||||||
if (iter !=0) {
|
size_t iter = currentlen / ST_MD5_BLOCK_SIZE;
|
||||||
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)(input + ST_MD5_BLOCK_SIZE - ctx->sbuf_len), (iter * ST_MD5_BLOCK_SIZE)) != 0) {
|
if (iter !=0) {
|
||||||
return; // Return error code here
|
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)(input + ST_MD5_BLOCK_SIZE - ctx->sbuf_len), (iter * ST_MD5_BLOCK_SIZE)) != 0) {
|
||||||
|
return; // Return error code here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// sbuf is completely accumulated, now copy up to 63 remaining bytes
|
||||||
|
ctx->sbuf_len = currentlen % ST_MD5_BLOCK_SIZE;
|
||||||
|
if (ctx->sbuf_len !=0) {
|
||||||
|
memcpy(ctx->sbuf, input + ilen - ctx->sbuf_len, ctx->sbuf_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sbuf is completely accumulated, now copy up to 63 remaining bytes
|
|
||||||
ctx->sbuf_len = currentlen % ST_MD5_BLOCK_SIZE;
|
if (st_md5_save_hw_context(ctx) != 1) {
|
||||||
if (ctx->sbuf_len !=0) {
|
return; // return HASH_BUSY timeout Error here
|
||||||
memcpy(ctx->sbuf, input + ilen - ctx->sbuf_len, ctx->sbuf_len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (st_md5_save_hw_context(ctx) != 1) {
|
|
||||||
return; // return HASH_BUSY timeout Error here
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
|
void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
|
||||||
|
@ -171,7 +169,7 @@ void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
|
||||||
return; // Return HASH_BUSY timout error here
|
return; // Return HASH_BUSY timout error here
|
||||||
}
|
}
|
||||||
/* Last accumulation for extra bytes in sbuf_len */
|
/* Last accumulation for extra bytes in sbuf_len */
|
||||||
/* This allows the HW flags to be in place in case mbedtls_sha256_update has not been called yet */
|
/* This sets HW flags in case mbedtls_md5_update has not been called yet */
|
||||||
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len) != 0) {
|
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len) != 0) {
|
||||||
return; // Return error code here
|
return; // Return error code here
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue