Feat: add detailed benchmar to reference impl
This commit is contained in:
parent
48dd446638
commit
d54e10fbe3
2 changed files with 9 additions and 0 deletions
|
@ -49,6 +49,8 @@ void MD2Final PROTO_LIST((unsigned char[16], MD2_CTX *));
|
|||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "../md2_common.h"
|
||||
|
||||
void md2_hash_ref(size_t len, const uint8_t buf[len], uint8_t out[16]);
|
||||
|
||||
#endif // MD2_REF_H
|
|
@ -83,6 +83,7 @@ void md2_hash_ref(size_t len, const uint8_t buf[len], uint8_t out[16]) {
|
|||
MD2Init(&context);
|
||||
MD2Update(&context, buf, len);
|
||||
MD2Final(out, &context);
|
||||
END_MARK
|
||||
}
|
||||
|
||||
/* MD2 initialization. Begins an MD2 operation, writing a new context.
|
||||
|
@ -169,23 +170,29 @@ unsigned char block[16];
|
|||
*/
|
||||
MD2_memcpy((POINTER)x, (POINTER)state, 16);
|
||||
MD2_memcpy((POINTER)x + 16, (POINTER)block, 16);
|
||||
FIRST_LOOP_START_MARK
|
||||
for (i = 0; i < 16; i++) x[i + 32] = state[i] ^ block[i];
|
||||
FIRST_LOOP_END_MARK
|
||||
|
||||
/* Encrypt block (18 rounds).
|
||||
*/
|
||||
t = 0;
|
||||
SECOND_LOOP_START_MARK
|
||||
for (i = 0; i < 18; i++) {
|
||||
for (j = 0; j < 48; j++) t = x[j] ^= PI_SUBST[t];
|
||||
t = (t + i) & 0xff;
|
||||
}
|
||||
SECOND_LOOP_END_MARK
|
||||
|
||||
/* Save new state */
|
||||
MD2_memcpy((POINTER)state, (POINTER)x, 16);
|
||||
|
||||
/* Update checksum.
|
||||
*/
|
||||
CHECKSUM_START_MARK
|
||||
t = checksum[15];
|
||||
for (i = 0; i < 16; i++) t = checksum[i] ^= PI_SUBST[block[i] ^ t];
|
||||
CHECKSUM_END_MARK
|
||||
|
||||
/* Zeroize sensitive information.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue