Skip to content

Commit aaa31eb

Browse files
committed
SM3 shared code: Uppercase size macros
1 parent e724754 commit aaa31eb

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/rawSM3_fmt_plug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ john_register_one(&fmt_sm3);
3838
#define BENCHMARK_COMMENT ""
3939
#define BENCHMARK_LENGTH 0x107
4040
#define PLAINTEXT_LENGTH MAX_PLAINTEXT_LENGTH
41-
#define BINARY_SIZE sm3_hash_length
41+
#define BINARY_SIZE SM3_HASH_LENGTH
4242
#define BINARY_ALIGN 4
4343
#define SALT_SIZE 0
4444
#define SALT_ALIGN 1
@@ -85,7 +85,7 @@ static int valid(char *ciphertext, struct fmt_main *self)
8585

8686
if (!strncmp(p, FORMAT_TAG, TAG_LENGTH))
8787
p += TAG_LENGTH;
88-
if (hexlenl(p, &extra) != (2 * sm3_hash_length) || extra)
88+
if (hexlenl(p, &extra) != (2 * SM3_HASH_LENGTH) || extra)
8989
return 0;
9090

9191
return 1;

src/sm3.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void sm3_compress_blocks(uint32_t hash[8], const uint8_t *data, size_t blocks)
184184
hash[6] ^= G;
185185
hash[7] ^= H;
186186

187-
data += sm3_block_size;
187+
data += SM3_BLOCK_SIZE;
188188
}
189189
}
190190

@@ -208,7 +208,7 @@ void sm3_update(sm3_ctx *ctx, const unsigned char *data, size_t size)
208208

209209
ctx->num &= 0x3f;
210210
if (ctx->num) {
211-
size_t left = sm3_block_size - ctx->num;
211+
size_t left = SM3_BLOCK_SIZE - ctx->num;
212212

213213
if (size < left) {
214214
memcpy(ctx->block + ctx->num, data, size);
@@ -223,12 +223,12 @@ void sm3_update(sm3_ctx *ctx, const unsigned char *data, size_t size)
223223
}
224224
}
225225

226-
blocks = size / sm3_block_size;
226+
blocks = size / SM3_BLOCK_SIZE;
227227
if (blocks) {
228228
sm3_compress_blocks(ctx->hash, data, blocks);
229229
ctx->num_blocks += blocks;
230-
data += sm3_block_size * blocks;
231-
size -= sm3_block_size * blocks;
230+
data += SM3_BLOCK_SIZE * blocks;
231+
size -= SM3_BLOCK_SIZE * blocks;
232232
}
233233

234234
ctx->num = size;
@@ -244,12 +244,12 @@ void sm3_final(sm3_ctx *ctx, unsigned char *result)
244244
ctx->num &= 0x3f;
245245
ctx->block[ctx->num] = 0x80;
246246

247-
if (ctx->num <= sm3_block_size - 9) {
248-
memset(ctx->block + ctx->num + 1, 0, sm3_block_size - ctx->num - 9);
247+
if (ctx->num <= SM3_BLOCK_SIZE - 9) {
248+
memset(ctx->block + ctx->num + 1, 0, SM3_BLOCK_SIZE - ctx->num - 9);
249249
} else {
250-
memset(ctx->block + ctx->num + 1, 0, sm3_block_size - ctx->num - 1);
250+
memset(ctx->block + ctx->num + 1, 0, SM3_BLOCK_SIZE - ctx->num - 1);
251251
sm3_compress_blocks(ctx->hash, ctx->block, 1);
252-
memset(ctx->block, 0, sm3_block_size - 8);
252+
memset(ctx->block, 0, SM3_BLOCK_SIZE - 8);
253253
}
254254

255255
PUTU32(ctx->block + 56, ctx->num_blocks >> 23);

src/sm3.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
extern "C" {
2020
#endif
2121

22-
#define sm3_block_size 64
23-
#define sm3_hash_length 32
22+
#define SM3_BLOCK_SIZE 64
23+
#define SM3_HASH_LENGTH 32
2424

2525
/* algorithm context */
2626
typedef struct sm3_ctx {
2727
uint32_t hash[8]; /* 256-bit hash */
28-
unsigned char block[sm3_block_size]; /* 512-bit message block */
28+
unsigned char block[SM3_BLOCK_SIZE]; /* 512-bit message block */
2929
uint64_t num_blocks; /* processed number of blocks */
3030
uint64_t num; /* index in the buffer of the last byte stored */
3131
} sm3_ctx;

0 commit comments

Comments
 (0)