Lines Matching refs:ctx

34 void sm3_init(struct sm3_context *ctx)  in sm3_init()  argument
36 ctx->total[0] = 0; in sm3_init()
37 ctx->total[1] = 0; in sm3_init()
39 ctx->state[0] = 0x7380166F; in sm3_init()
40 ctx->state[1] = 0x4914B2B9; in sm3_init()
41 ctx->state[2] = 0x172442D7; in sm3_init()
42 ctx->state[3] = 0xDA8A0600; in sm3_init()
43 ctx->state[4] = 0xA96F30BC; in sm3_init()
44 ctx->state[5] = 0x163138AA; in sm3_init()
45 ctx->state[6] = 0xE38DEE4D; in sm3_init()
46 ctx->state[7] = 0xB0FB0E4E; in sm3_init()
49 static void sm3_process(struct sm3_context *ctx, const uint8_t data[64]) in sm3_process() argument
108 A = ctx->state[0]; in sm3_process()
109 B = ctx->state[1]; in sm3_process()
110 C = ctx->state[2]; in sm3_process()
111 D = ctx->state[3]; in sm3_process()
112 E = ctx->state[4]; in sm3_process()
113 F = ctx->state[5]; in sm3_process()
114 G = ctx->state[6]; in sm3_process()
115 H = ctx->state[7]; in sm3_process()
147 ctx->state[0] ^= A; in sm3_process()
148 ctx->state[1] ^= B; in sm3_process()
149 ctx->state[2] ^= C; in sm3_process()
150 ctx->state[3] ^= D; in sm3_process()
151 ctx->state[4] ^= E; in sm3_process()
152 ctx->state[5] ^= F; in sm3_process()
153 ctx->state[6] ^= G; in sm3_process()
154 ctx->state[7] ^= H; in sm3_process()
157 void sm3_update(struct sm3_context *ctx, const uint8_t *input, size_t ilen) in sm3_update() argument
165 left = ctx->total[0] & 0x3F; in sm3_update()
168 ctx->total[0] += ilen; in sm3_update()
170 if (ctx->total[0] < ilen) in sm3_update()
171 ctx->total[1]++; in sm3_update()
174 memcpy(ctx->buffer + left, input, fill); in sm3_update()
175 sm3_process(ctx, ctx->buffer); in sm3_update()
182 sm3_process(ctx, input); in sm3_update()
188 memcpy(ctx->buffer + left, input, ilen); in sm3_update()
198 void sm3_final(struct sm3_context *ctx, uint8_t output[32]) in sm3_final() argument
204 high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); in sm3_final()
205 low = ctx->total[0] << 3; in sm3_final()
210 last = ctx->total[0] & 0x3F; in sm3_final()
213 sm3_update(ctx, sm3_padding, padn); in sm3_final()
214 sm3_update(ctx, msglen, 8); in sm3_final()
216 PUT_UINT32_BE(ctx->state[0], output, 0); in sm3_final()
217 PUT_UINT32_BE(ctx->state[1], output, 4); in sm3_final()
218 PUT_UINT32_BE(ctx->state[2], output, 8); in sm3_final()
219 PUT_UINT32_BE(ctx->state[3], output, 12); in sm3_final()
220 PUT_UINT32_BE(ctx->state[4], output, 16); in sm3_final()
221 PUT_UINT32_BE(ctx->state[5], output, 20); in sm3_final()
222 PUT_UINT32_BE(ctx->state[6], output, 24); in sm3_final()
223 PUT_UINT32_BE(ctx->state[7], output, 28); in sm3_final()
228 struct sm3_context ctx = { }; in sm3() local
230 sm3_init(&ctx); in sm3()
231 sm3_update(&ctx, input, ilen); in sm3()
232 sm3_final(&ctx, output); in sm3()
234 memzero_explicit(&ctx, sizeof(ctx)); in sm3()
237 void sm3_hmac_init(struct sm3_context *ctx, const uint8_t *key, size_t keylen) in sm3_hmac_init() argument
248 memset(ctx->ipad, 0x36, 64); in sm3_hmac_init()
249 memset(ctx->opad, 0x5C, 64); in sm3_hmac_init()
252 ctx->ipad[i] ^= key[i]; in sm3_hmac_init()
253 ctx->opad[i] ^= key[i]; in sm3_hmac_init()
256 sm3_init(ctx); in sm3_hmac_init()
257 sm3_update(ctx, ctx->ipad, 64); in sm3_hmac_init()
262 void sm3_hmac_update(struct sm3_context *ctx, const uint8_t *input, size_t ilen) in sm3_hmac_update() argument
264 sm3_update(ctx, input, ilen); in sm3_hmac_update()
267 void sm3_hmac_final(struct sm3_context *ctx, uint8_t output[32]) in sm3_hmac_final() argument
271 sm3_final(ctx, tmpbuf); in sm3_hmac_final()
272 sm3_init(ctx); in sm3_hmac_final()
273 sm3_update(ctx, ctx->opad, 64); in sm3_hmac_final()
274 sm3_update(ctx, tmpbuf, 32); in sm3_hmac_final()
275 sm3_final(ctx, output); in sm3_hmac_final()
283 struct sm3_context ctx; in sm3_hmac() local
285 sm3_hmac_init(&ctx, key, keylen); in sm3_hmac()
286 sm3_hmac_update(&ctx, input, ilen); in sm3_hmac()
287 sm3_hmac_final(&ctx, output); in sm3_hmac()
289 memzero_explicit(&ctx, sizeof(ctx)); in sm3_hmac()