View | Details | Raw Unified | Return to bug 202365
Collapse All | Expand All

(-)patch/g_eli_crypto.c (-13 / +16 lines)
Lines 240-246 Link Here
240
g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey,
240
g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey,
241
    size_t hkeylen)
241
    size_t hkeylen)
242
{
242
{
243
	u_char k_ipad[128], key[128];
243
	u_char k_ipad[128], k_opad[128], key[128];
244
	SHA512_CTX lctx;
244
	SHA512_CTX lctx;
245
	u_int i;
245
	u_int i;
246
246
Lines 259-271 Link Here
259
	/* XOR key with ipad and opad values. */
259
	/* XOR key with ipad and opad values. */
260
	for (i = 0; i < sizeof(key); i++) {
260
	for (i = 0; i < sizeof(key); i++) {
261
		k_ipad[i] = key[i] ^ 0x36;
261
		k_ipad[i] = key[i] ^ 0x36;
262
		ctx->k_opad[i] = key[i] ^ 0x5c;
262
		k_opad[i] = key[i] ^ 0x5c;
263
	}
263
	}
264
	bzero(key, sizeof(key));
264
	bzero(key, sizeof(key));
265
	/* Perform inner SHA512. */
265
	/* Start inner SHA512. */
266
	SHA512_Init(&ctx->shactx);
266
	SHA512_Init(&ctx->innerctx);
267
	SHA512_Update(&ctx->shactx, k_ipad, sizeof(k_ipad));
267
	SHA512_Update(&ctx->innerctx, k_ipad, sizeof(k_ipad));
268
	bzero(k_ipad, sizeof(k_ipad));
268
	bzero(k_ipad, sizeof(k_ipad));
269
	/* Start outer SHA512. */
270
	SHA512_Init(&ctx->outerctx);
271
	SHA512_Update(&ctx->outerctx, k_opad, sizeof(k_opad));
272
	bzero(k_opad, sizeof(k_opad));
269
}
273
}
270
274
271
void
275
void
Lines 280-295 Link Here
280
g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize)
284
g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize)
281
{
285
{
282
	u_char digest[SHA512_MDLEN];
286
	u_char digest[SHA512_MDLEN];
283
	SHA512_CTX lctx;
284
287
285
	SHA512_Final(digest, &ctx->shactx);
288
	/* Complete inner hash */
286
	/* Perform outer SHA512. */
289
	SHA512_Final(digest, &ctx->innerctx);
287
	SHA512_Init(&lctx);
290
	
288
	SHA512_Update(&lctx, ctx->k_opad, sizeof(ctx->k_opad));
291
	/* Complete outer hash */
292
	SHA512_Update(&ctx->outerctx, digest, sizeof(digest));
293
	SHA512_Final(digest, &ctx->outerctx);
294
	
289
	bzero(ctx, sizeof(*ctx));
295
	bzero(ctx, sizeof(*ctx));
290
	SHA512_Update(&lctx, digest, sizeof(digest));
291
	SHA512_Final(digest, &lctx);
292
	bzero(&lctx, sizeof(lctx));
293
	/* mdsize == 0 means "Give me the whole hash!" */
296
	/* mdsize == 0 means "Give me the whole hash!" */
294
	if (mdsize == 0)
297
	if (mdsize == 0)
295
		mdsize = SHA512_MDLEN;
298
		mdsize = SHA512_MDLEN;
(-)patch/g_eli.h (-2 / +2 lines)
Lines 605-612 Link Here
605
    const u_char *key, size_t keysize);
605
    const u_char *key, size_t keysize);
606
606
607
struct hmac_ctx {
607
struct hmac_ctx {
608
	SHA512_CTX	shactx;
608
	SHA512_CTX	innerctx;
609
	u_char		k_opad[128];
609
	SHA512_CTX	outerctx;
610
};
610
};
611
611
612
void g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey,
612
void g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey,
(-)patch/pkcs5v2.c (-4 / +11 lines)
Lines 56-61 Link Here
56
	uint8_t *counter, *keyp;
56
	uint8_t *counter, *keyp;
57
	u_int i, bsize, passlen;
57
	u_int i, bsize, passlen;
58
	uint32_t count;
58
	uint32_t count;
59
	struct hmac_ctx startpoint, ctx;
59
60
60
	passlen = strlen(passphrase);
61
	passlen = strlen(passphrase);
61
	bzero(key, keylen);
62
	bzero(key, keylen);
Lines 70-85 Link Here
70
		counter[1] = (count >> 16) & 0xff;
71
		counter[1] = (count >> 16) & 0xff;
71
		counter[2] = (count >> 8) & 0xff;
72
		counter[2] = (count >> 8) & 0xff;
72
		counter[3] = count & 0xff;
73
		counter[3] = count & 0xff;
73
		g_eli_crypto_hmac(passphrase, passlen, saltcount,
74
74
		    sizeof(saltcount), md, 0);
75
		g_eli_crypto_hmac_init(&startpoint, passphrase, passlen);
76
		ctx = startpoint;
77
		g_eli_crypto_hmac_update(&ctx, saltcount, sizeof(saltcount));
78
		g_eli_crypto_hmac_final(&ctx, md, sizeof(md));
75
		xor(keyp, md, bsize);
79
		xor(keyp, md, bsize);
76
80
77
		for(i = 1; i < iterations; i++) {
81
		for(i = 1; i < iterations; i++) {
78
			g_eli_crypto_hmac(passphrase, passlen, md, sizeof(md),
82
			ctx = startpoint;
79
			    md, 0);
83
			g_eli_crypto_hmac_update(&ctx, md, sizeof(md));
84
			g_eli_crypto_hmac_final(&ctx, md, sizeof(md));
80
			xor(keyp, md, bsize);
85
			xor(keyp, md, bsize);
81
		}
86
		}
82
	}
87
	}
88
	bzero(&startpoint, sizeof(startpoint));
89
	bzero(&ctx, sizeof(ctx));
83
}
90
}
84
91
85
#ifndef _KERNEL
92
#ifndef _KERNEL

Return to bug 202365