Skip to content

Commit 5aad144

Browse files
committed
fix F-1236: Copy-Paste Error in #endif Comment: AESCBC Instead of AESCFB Info Assigned
fix F-3291: Copy-paste error in linuxkm_test_aesgcm error message uses WOLFKM_AESCBC_DRIVER fix F-1431: AES-GCM RFC4106 SetKey Uses memcpy Instead of XMEMCPY for Nonce Copy (note, for F-1431, changed all relevant memset() and memcpy() calls in linuxkm/ to XMEMSET() and XMEMCPY() respectively.)
1 parent 3c9996e commit 5aad144

9 files changed

Lines changed: 137 additions & 137 deletions

linuxkm/linuxkm_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ ssize_t wc_reloc_normalize_segment(
197197
return i;
198198

199199
WC_SANITIZE_DISABLE();
200-
memcpy(seg_out, seg_in, *seg_in_out_len);
200+
XMEMCPY(seg_out, seg_in, *seg_in_out_len);
201201
WC_SANITIZE_ENABLE();
202202

203203
/* note, if there are no relocations in the src seg, the loop isn't entered

linuxkm/lkcapi_aes_glue.c

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ static struct skcipher_alg cfbAesAlg = {
945945
};
946946
static int cfbAesAlg_loaded = 0;
947947

948-
#endif /* LINUXKM_LKCAPI_REGISTER_AESCBC */
948+
#endif /* LINUXKM_LKCAPI_REGISTER_AESCFB */
949949

950950
#if defined(LINUXKM_LKCAPI_REGISTER_AESGCM) || \
951951
defined(LINUXKM_LKCAPI_REGISTER_AESGCM_RFC4106)
@@ -1016,7 +1016,7 @@ static int km_AesGcmSetKey_Rfc4106(struct crypto_aead *tfm, const u8 *in_key,
10161016
if (key_len < 4)
10171017
return -EINVAL;
10181018
key_len -= 4;
1019-
memcpy(ctx->rfc4106_nonce, in_key + key_len, 4);
1019+
XMEMCPY(ctx->rfc4106_nonce, in_key + key_len, 4);
10201020

10211021
err = wc_AesGcmSetKey(ctx->aes_encrypt, in_key, key_len);
10221022

@@ -1171,8 +1171,8 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
11711171
}
11721172
assoclen -= 8;
11731173

1174-
memcpy(rfc4106_iv, ctx->rfc4106_nonce, 4);
1175-
memcpy(rfc4106_iv + 4, walk.iv, 8);
1174+
XMEMCPY(rfc4106_iv, ctx->rfc4106_nonce, 4);
1175+
XMEMCPY(rfc4106_iv + 4, walk.iv, 8);
11761176
err = wc_AesGcmInit(aes_copy, NULL /*key*/, 0 /*keylen*/, rfc4106_iv,
11771177
GCM_NONCE_MID_SZ);
11781178
}
@@ -1396,8 +1396,8 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
13961396
}
13971397
assoclen -= 8;
13981398

1399-
memcpy(rfc4106_iv, ctx->rfc4106_nonce, 4);
1400-
memcpy(rfc4106_iv + 4, sk_walk.iv, 8);
1399+
XMEMCPY(rfc4106_iv, ctx->rfc4106_nonce, 4);
1400+
XMEMCPY(rfc4106_iv + 4, sk_walk.iv, 8);
14011401
}
14021402
#else
14031403
(void)rfc4106_p;
@@ -1681,7 +1681,7 @@ static int km_AesCcmSetKey_Rfc4309(struct crypto_aead *tfm, const u8 *in_key,
16811681
if (key_len < 3)
16821682
return -EINVAL;
16831683
key_len -= 3;
1684-
memcpy(ctx->rfc4309_nonce, in_key + key_len, 3);
1684+
XMEMCPY(ctx->rfc4309_nonce, in_key + key_len, 3);
16851685

16861686
err = wc_AesCcmSetKey(ctx->aes_encrypt, in_key, key_len);
16871687

@@ -1878,8 +1878,8 @@ static int AesCcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4309_p)
18781878
}
18791879
assoclen -= 8;
18801880

1881-
memcpy(rfc4309_iv, ctx->rfc4309_nonce, 3);
1882-
memcpy(rfc4309_iv + 3, sk_walk.iv, 8);
1881+
XMEMCPY(rfc4309_iv, ctx->rfc4309_nonce, 3);
1882+
XMEMCPY(rfc4309_iv + 3, sk_walk.iv, 8);
18831883
nonce = rfc4309_iv;
18841884
nonceSz = 11;
18851885
}
@@ -3125,7 +3125,7 @@ static int linuxkm_test_aescbc(void)
31253125
goto test_cbc_end;
31263126
}
31273127

3128-
memcpy(dec2, p_vector, sizeof(p_vector));
3128+
XMEMCPY(dec2, p_vector, sizeof(p_vector));
31293129

31303130
tfm = crypto_alloc_skcipher(WOLFKM_AESCBC_NAME, 0, 0);
31313131
if (IS_ERR(tfm)) {
@@ -3181,7 +3181,7 @@ static int linuxkm_test_aescbc(void)
31813181
goto test_cbc_end;
31823182
}
31833183

3184-
memset(dec2, 0, sizeof(p_vector));
3184+
XMEMSET(dec2, 0, sizeof(p_vector));
31853185
sg_init_one(&src, enc2, sizeof(p_vector));
31863186
sg_init_one(&dst, dec2, sizeof(p_vector));
31873187

@@ -3338,7 +3338,7 @@ static int linuxkm_test_aescfb(void)
33383338
goto test_cfb_end;
33393339
}
33403340

3341-
memcpy(dec2, p_vector, sizeof(p_vector));
3341+
XMEMCPY(dec2, p_vector, sizeof(p_vector));
33423342

33433343
tfm = crypto_alloc_skcipher(WOLFKM_AESCFB_NAME, 0, 0);
33443344
if (IS_ERR(tfm)) {
@@ -3385,7 +3385,7 @@ static int linuxkm_test_aescfb(void)
33853385
goto test_cfb_end;
33863386
}
33873387

3388-
memset(dec2, 0, sizeof(p_vector));
3388+
XMEMSET(dec2, 0, sizeof(p_vector));
33893389
sg_init_one(&src, enc2, sizeof(p_vector));
33903390
sg_init_one(&dst, dec2, sizeof(p_vector));
33913391

@@ -3574,17 +3574,17 @@ static int linuxkm_test_aesgcm(void)
35743574
ret = MEMORY_E;
35753575
goto test_gcm_end;
35763576
}
3577-
memset(assoc2, 0, sizeof(assoc));
3578-
memcpy(assoc2, assoc, sizeof(assoc));
3577+
XMEMSET(assoc2, 0, sizeof(assoc));
3578+
XMEMCPY(assoc2, assoc, sizeof(assoc));
35793579

35803580
iv = malloc(WC_AES_BLOCK_SIZE);
35813581
if (! iv) {
35823582
pr_err("error: malloc failed\n");
35833583
ret = MEMORY_E;
35843584
goto test_gcm_end;
35853585
}
3586-
memset(iv, 0, WC_AES_BLOCK_SIZE);
3587-
memcpy(iv, ivstr, GCM_NONCE_MID_SZ);
3586+
XMEMSET(iv, 0, WC_AES_BLOCK_SIZE);
3587+
XMEMCPY(iv, ivstr, GCM_NONCE_MID_SZ);
35883588

35893589
enc2 = malloc(decryptLen);
35903590
if (! enc2) {
@@ -3600,13 +3600,13 @@ static int linuxkm_test_aesgcm(void)
36003600
goto test_gcm_end;
36013601
}
36023602

3603-
memset(enc2, 0, decryptLen);
3604-
memset(dec2, 0, decryptLen);
3605-
memcpy(dec2, p_vector, sizeof(p_vector));
3603+
XMEMSET(enc2, 0, decryptLen);
3604+
XMEMSET(dec2, 0, decryptLen);
3605+
XMEMCPY(dec2, p_vector, sizeof(p_vector));
36063606

36073607
tfm = crypto_alloc_aead(WOLFKM_AESGCM_NAME, 0, 0);
36083608
if (IS_ERR(tfm)) {
3609-
pr_err("error: allocating AES skcipher algorithm %s failed: %ld\n",
3609+
pr_err("error: allocating AES aead algorithm %s failed: %ld\n",
36103610
WOLFKM_AESGCM_DRIVER, PTR_ERR(tfm));
36113611
tfm = NULL;
36123612
goto test_gcm_end;
@@ -3632,7 +3632,7 @@ static int linuxkm_test_aesgcm(void)
36323632
if (! req) {
36333633
ret = -ENOMEM;
36343634
pr_err("error: allocating AES aead request %s failed.\n",
3635-
WOLFKM_AESCBC_DRIVER);
3635+
WOLFKM_AESGCM_DRIVER);
36363636
goto test_gcm_end;
36373637
}
36383638

@@ -3684,7 +3684,7 @@ static int linuxkm_test_aesgcm(void)
36843684
}
36853685

36863686
/* Now decrypt crypto request. Reverse src and dst. */
3687-
memset(dec2, 0, decryptLen);
3687+
XMEMSET(dec2, 0, decryptLen);
36883688
aead_request_set_ad(req, sizeof(assoc));
36893689
aead_request_set_crypt(req, dst, src, decryptLen, iv);
36903690

@@ -4253,13 +4253,13 @@ static int aes_xts_128_test(void)
42534253
goto test_xts_end;
42544254
}
42554255

4256-
memcpy(dec2, p1, sizeof(p1));
4257-
memset(enc2, 0, sizeof(p1));
4256+
XMEMCPY(dec2, p1, sizeof(p1));
4257+
XMEMSET(enc2, 0, sizeof(p1));
42584258

42594259
sg_init_one(src, dec2, sizeof(p1));
42604260
sg_init_one(dst, enc2, sizeof(p1));
42614261

4262-
memcpy(stream.tweak_block, i1, sizeof(stream.tweak_block));
4262+
XMEMCPY(stream.tweak_block, i1, sizeof(stream.tweak_block));
42634263
skcipher_request_set_crypt(req, src, dst, sizeof(p1), stream.tweak_block);
42644264

42654265
ret = crypto_skcipher_encrypt(req);
@@ -4276,11 +4276,11 @@ static int aes_xts_128_test(void)
42764276
goto test_xts_end;
42774277
}
42784278

4279-
memset(dec2, 0, sizeof(p1));
4279+
XMEMSET(dec2, 0, sizeof(p1));
42804280
sg_init_one(src, enc2, sizeof(p1));
42814281
sg_init_one(dst, dec2, sizeof(p1));
42824282

4283-
memcpy(stream.tweak_block, i1, sizeof(stream.tweak_block));
4283+
XMEMCPY(stream.tweak_block, i1, sizeof(stream.tweak_block));
42844284
skcipher_request_set_crypt(req, src, dst, sizeof(p1), stream.tweak_block);
42854285

42864286
ret = crypto_skcipher_decrypt(req);
@@ -4297,13 +4297,13 @@ static int aes_xts_128_test(void)
42974297
goto test_xts_end;
42984298
}
42994299

4300-
memcpy(dec2, pp, sizeof(pp));
4301-
memset(enc2, 0, sizeof(pp));
4300+
XMEMCPY(dec2, pp, sizeof(pp));
4301+
XMEMSET(enc2, 0, sizeof(pp));
43024302

43034303
sg_init_one(src, dec2, sizeof(pp));
43044304
sg_init_one(dst, enc2, sizeof(pp));
43054305

4306-
memcpy(stream.tweak_block, i1, sizeof(stream.tweak_block));
4306+
XMEMCPY(stream.tweak_block, i1, sizeof(stream.tweak_block));
43074307
skcipher_request_set_crypt(req, src, dst, sizeof(pp), stream.tweak_block);
43084308

43094309
ret = crypto_skcipher_encrypt(req);
@@ -4320,11 +4320,11 @@ static int aes_xts_128_test(void)
43204320
goto test_xts_end;
43214321
}
43224322

4323-
memset(dec2, 0, sizeof(pp));
4323+
XMEMSET(dec2, 0, sizeof(pp));
43244324
sg_init_one(src, enc2, sizeof(pp));
43254325
sg_init_one(dst, dec2, sizeof(pp));
43264326

4327-
memcpy(stream.tweak_block, i1, sizeof(stream.tweak_block));
4327+
XMEMCPY(stream.tweak_block, i1, sizeof(stream.tweak_block));
43284328
skcipher_request_set_crypt(req, src, dst, sizeof(pp), stream.tweak_block);
43294329

43304330
ret = crypto_skcipher_decrypt(req);
@@ -4749,13 +4749,13 @@ static int aes_xts_256_test(void)
47494749
goto test_xts_end;
47504750
}
47514751

4752-
memcpy(dec2, p1, sizeof(p1));
4753-
memset(enc2, 0, sizeof(p1));
4752+
XMEMCPY(dec2, p1, sizeof(p1));
4753+
XMEMSET(enc2, 0, sizeof(p1));
47544754

47554755
sg_init_one(src, dec2, sizeof(p1));
47564756
sg_init_one(dst, enc2, sizeof(p1));
47574757

4758-
memcpy(stream.tweak_block, i1, sizeof(stream.tweak_block));
4758+
XMEMCPY(stream.tweak_block, i1, sizeof(stream.tweak_block));
47594759
skcipher_request_set_crypt(req, src, dst, sizeof(p1), stream.tweak_block);
47604760

47614761
ret = crypto_skcipher_encrypt(req);
@@ -4772,11 +4772,11 @@ static int aes_xts_256_test(void)
47724772
goto test_xts_end;
47734773
}
47744774

4775-
memset(dec2, 0, sizeof(p1));
4775+
XMEMSET(dec2, 0, sizeof(p1));
47764776
sg_init_one(src, enc2, sizeof(p1));
47774777
sg_init_one(dst, dec2, sizeof(p1));
47784778

4779-
memcpy(stream.tweak_block, i1, sizeof(stream.tweak_block));
4779+
XMEMCPY(stream.tweak_block, i1, sizeof(stream.tweak_block));
47804780
skcipher_request_set_crypt(req, src, dst, sizeof(p1), stream.tweak_block);
47814781

47824782
ret = crypto_skcipher_decrypt(req);
@@ -4793,13 +4793,13 @@ static int aes_xts_256_test(void)
47934793
goto test_xts_end;
47944794
}
47954795

4796-
memcpy(dec2, pp, sizeof(pp));
4797-
memset(enc2, 0, sizeof(pp));
4796+
XMEMCPY(dec2, pp, sizeof(pp));
4797+
XMEMSET(enc2, 0, sizeof(pp));
47984798

47994799
sg_init_one(src, dec2, sizeof(pp));
48004800
sg_init_one(dst, enc2, sizeof(pp));
48014801

4802-
memcpy(stream.tweak_block, i1, sizeof(stream.tweak_block));
4802+
XMEMCPY(stream.tweak_block, i1, sizeof(stream.tweak_block));
48034803
skcipher_request_set_crypt(req, src, dst, sizeof(pp), stream.tweak_block);
48044804

48054805
ret = crypto_skcipher_encrypt(req);
@@ -4816,11 +4816,11 @@ static int aes_xts_256_test(void)
48164816
goto test_xts_end;
48174817
}
48184818

4819-
memset(dec2, 0, sizeof(pp));
4819+
XMEMSET(dec2, 0, sizeof(pp));
48204820
sg_init_one(src, enc2, sizeof(pp));
48214821
sg_init_one(dst, dec2, sizeof(pp));
48224822

4823-
memcpy(stream.tweak_block, i1, sizeof(stream.tweak_block));
4823+
XMEMCPY(stream.tweak_block, i1, sizeof(stream.tweak_block));
48244824
skcipher_request_set_crypt(req, src, dst, sizeof(pp), stream.tweak_block);
48254825

48264826
ret = crypto_skcipher_decrypt(req);

linuxkm/lkcapi_dh_glue.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,18 @@ static int km_dh_decode_secret(const u8 * buf, unsigned int len,
329329

330330
/* the type of secret should be the first byte. */
331331
ptr = buf;
332-
memcpy(&secret, ptr, sizeof(secret));
332+
XMEMCPY(&secret, ptr, sizeof(secret));
333333
ptr += sizeof(secret);
334334
if (secret.type != CRYPTO_KPP_SECRET_TYPE_DH) {
335335
return -EINVAL;
336336
}
337337

338338
/* all three of these fields will be present */
339-
memcpy(&params->key_size, ptr, sizeof(params->key_size));
339+
XMEMCPY(&params->key_size, ptr, sizeof(params->key_size));
340340
ptr += sizeof(params->key_size);
341-
memcpy(&params->p_size, ptr, sizeof(params->p_size));
341+
XMEMCPY(&params->p_size, ptr, sizeof(params->p_size));
342342
ptr += sizeof(params->p_size);
343-
memcpy(&params->g_size, ptr, sizeof(params->g_size));
343+
XMEMCPY(&params->g_size, ptr, sizeof(params->g_size));
344344
ptr += sizeof(params->g_size);
345345

346346
/* Calculate expected len based on provided 3 fields. Verify
@@ -411,15 +411,15 @@ static int km_dh_alloc_keys(struct km_dh_ctx * ctx)
411411
goto alloc_keys_end;
412412
}
413413

414-
memset(ctx->priv_key, 0, ctx->priv_len);
414+
XMEMSET(ctx->priv_key, 0, ctx->priv_len);
415415

416416
ctx->pub_key = malloc(ctx->pub_len);
417417
if (!ctx->pub_key) {
418418
err = -ENOMEM;
419419
goto alloc_keys_end;
420420
}
421421

422-
memset(ctx->pub_key, 0, ctx->pub_len);
422+
XMEMSET(ctx->pub_key, 0, ctx->pub_len);
423423

424424
alloc_keys_end:
425425
if (err) {
@@ -485,7 +485,7 @@ static int km_dh_set_secret(struct crypto_kpp *tfm, const void *buf,
485485
struct dh params;
486486

487487
ctx = kpp_tfm_ctx(tfm);
488-
memset(&params, 0, sizeof(params));
488+
XMEMSET(&params, 0, sizeof(params));
489489

490490
if (km_dh_decode_secret(buf, len, &params) < 0) {
491491
#ifdef WOLFKM_DEBUG_DH
@@ -591,7 +591,7 @@ static int km_ffdhe_set_secret(struct crypto_kpp *tfm, const void *buf,
591591
struct dh params;
592592

593593
ctx = kpp_tfm_ctx(tfm);
594-
memset(&params, 0, sizeof(params));
594+
XMEMSET(&params, 0, sizeof(params));
595595

596596
/* buf is optional for ffdhe */
597597
if (buf) {
@@ -659,7 +659,7 @@ static int km_ffdhe_set_secret(struct crypto_kpp *tfm, const void *buf,
659659
#endif
660660

661661
memmove(ctx->pub_key + pad_len, ctx->pub_key, ctx->pub_len);
662-
memset(ctx->pub_key, 0, pad_len);
662+
XMEMSET(ctx->pub_key, 0, pad_len);
663663

664664
ctx->pub_len += pad_len;
665665
}
@@ -760,7 +760,7 @@ static int km_ffdhe_init(struct crypto_kpp *tfm, int name, word32 nbits)
760760
int key_inited = 0;
761761

762762
ctx = kpp_tfm_ctx(tfm);
763-
memset(ctx, 0, sizeof(struct km_dh_ctx));
763+
XMEMSET(ctx, 0, sizeof(struct km_dh_ctx));
764764
ctx->name = name;
765765
ctx->nbits = nbits;
766766

@@ -885,7 +885,7 @@ static int km_dh_gen_pub(struct kpp_request *req)
885885
}
886886

887887
if (ctx->has_pub_key == 0) {
888-
memset(ctx->pub_key, 0, ctx->pub_len);
888+
XMEMSET(ctx->pub_key, 0, ctx->pub_len);
889889

890890
err = wc_DhGeneratePublic(ctx->key, ctx->priv_key, ctx->priv_len,
891891
ctx->pub_key, &ctx->pub_len);
@@ -965,7 +965,7 @@ static int km_dh_compute_shared_secret(struct kpp_request *req)
965965
goto dh_shared_secret_end;
966966
}
967967

968-
memset(pub, 0, pub_len);
968+
XMEMSET(pub, 0, pub_len);
969969

970970
/* copy req->src to pub */
971971
scatterwalk_map_and_copy(pub, req->src, 0, req->src_len, 0);
@@ -2941,7 +2941,7 @@ static int linuxkm_test_kpp_driver(const char * driver,
29412941
goto test_kpp_end;
29422942
}
29432943

2944-
memset(dst_buf, 0, dst_len);
2944+
XMEMSET(dst_buf, 0, dst_len);
29452945

29462946
/* generate pub key from input, and verify matches expected. */
29472947
kpp_request_set_input(req, NULL, 0);
@@ -2968,7 +2968,7 @@ static int linuxkm_test_kpp_driver(const char * driver,
29682968
goto test_kpp_end;
29692969
}
29702970

2971-
memcpy(src_buf, b_pub, pub_len);
2971+
XMEMCPY(src_buf, b_pub, pub_len);
29722972

29732973
/* generate shared secret, verify matches expected value. */
29742974
sg_init_one(&src, src_buf, src_len);

0 commit comments

Comments
 (0)