Added AES+GHASH implementation using AES-NI opcodes; also ARM-Thumb assembly for faster Montgomery multiplication on Cortex-M0+. Added selection functions for "default" implementations.
This commit is contained in:
parent
556e525d62
commit
5f045c7599
58 changed files with 3012 additions and 395 deletions
|
|
@ -591,7 +591,7 @@ test_HMAC_CT(const br_hash_class *digest_class,
|
|||
|
||||
br_hmac_key_init(&kc, digest_class, key, key_len);
|
||||
|
||||
for (u = 0; u < 130; u ++) {
|
||||
for (u = 0; u < 2; u ++) {
|
||||
for (v = 0; v < 130; v ++) {
|
||||
size_t min_len, max_len;
|
||||
size_t w;
|
||||
|
|
@ -3157,7 +3157,6 @@ test_AES_generic(char *name,
|
|||
data_len = hextobin(plain, KAT_AES_CTR[u + 2]);
|
||||
hextobin(cipher, KAT_AES_CTR[u + 3]);
|
||||
vc->init(xc, key, key_len);
|
||||
|
||||
memcpy(buf, plain, data_len);
|
||||
vc->run(xc, iv, 1, buf, data_len);
|
||||
check_equals("KAT CTR AES (1)", buf, cipher, data_len);
|
||||
|
|
@ -3271,6 +3270,33 @@ test_AES_ct64(void)
|
|||
1, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
test_AES_x86ni(void)
|
||||
{
|
||||
const br_block_cbcenc_class *x_cbcenc;
|
||||
const br_block_cbcdec_class *x_cbcdec;
|
||||
const br_block_ctr_class *x_ctr;
|
||||
int hcbcenc, hcbcdec, hctr;
|
||||
|
||||
x_cbcenc = br_aes_x86ni_cbcenc_get_vtable();
|
||||
x_cbcdec = br_aes_x86ni_cbcdec_get_vtable();
|
||||
x_ctr = br_aes_x86ni_ctr_get_vtable();
|
||||
hcbcenc = (x_cbcenc != NULL);
|
||||
hcbcdec = (x_cbcdec != NULL);
|
||||
hctr = (x_ctr != NULL);
|
||||
if (hcbcenc != hctr || hcbcdec != hctr) {
|
||||
fprintf(stderr, "AES_x86ni availability mismatch (%d/%d/%d)\n",
|
||||
hcbcenc, hcbcdec, hctr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (hctr) {
|
||||
test_AES_generic("AES_x86ni",
|
||||
x_cbcenc, x_cbcdec, x_ctr, 1, 1);
|
||||
} else {
|
||||
printf("Test AES_x86ni: UNAVAILABLE\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* DES known-answer tests. Order: plaintext, key, ciphertext.
|
||||
* (mostly from NIST SP 800-20).
|
||||
|
|
@ -4671,6 +4697,19 @@ test_GHASH_ctmul64(void)
|
|||
test_GHASH("GHASH_ctmul64", br_ghash_ctmul64);
|
||||
}
|
||||
|
||||
static void
|
||||
test_GHASH_pclmul(void)
|
||||
{
|
||||
br_ghash gh;
|
||||
|
||||
gh = br_ghash_pclmul_get();
|
||||
if (gh == 0) {
|
||||
printf("Test GHASH_pclmul: UNAVAILABLE\n");
|
||||
} else {
|
||||
test_GHASH("GHASH_pclmul", gh);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_EC_inner(const char *sk, const char *sU,
|
||||
const br_ec_impl *impl, int curve)
|
||||
|
|
@ -5559,6 +5598,7 @@ static const struct {
|
|||
STU(AES_small),
|
||||
STU(AES_ct),
|
||||
STU(AES_ct64),
|
||||
STU(AES_x86ni),
|
||||
STU(DES_tab),
|
||||
STU(DES_ct),
|
||||
STU(ChaCha20_ct),
|
||||
|
|
@ -5571,6 +5611,7 @@ static const struct {
|
|||
STU(GHASH_ctmul),
|
||||
STU(GHASH_ctmul32),
|
||||
STU(GHASH_ctmul64),
|
||||
STU(GHASH_pclmul),
|
||||
STU(EC_prime_i15),
|
||||
STU(EC_prime_i31),
|
||||
STU(EC_p256_m15),
|
||||
|
|
|
|||
|
|
@ -88,7 +88,12 @@ test_speed_ ## fname(void) \
|
|||
memset(key, 'T', sizeof key); \
|
||||
memset(buf, 'P', sizeof buf); \
|
||||
memset(iv, 'X', sizeof iv); \
|
||||
vt = &br_ ## cname ## _cbc ## dir ## _vtable; \
|
||||
vt = br_ ## cname ## _cbc ## dir ## _get_vtable(); \
|
||||
if (vt == NULL) { \
|
||||
printf("%-30s UNAVAILABLE\n", #Name); \
|
||||
fflush(stdout); \
|
||||
return; \
|
||||
} \
|
||||
for (i = 0; i < 10; i ++) { \
|
||||
vt->init(&ec.vtable, key, sizeof key); \
|
||||
vt->run(&ec.vtable, iv, buf, sizeof buf); \
|
||||
|
|
@ -132,7 +137,12 @@ test_speed_ ## fname(void) \
|
|||
memset(key, 'T', sizeof key); \
|
||||
memset(buf, 'P', sizeof buf); \
|
||||
memset(iv, 'X', sizeof iv); \
|
||||
vt = &br_ ## cname ## _ctr_vtable; \
|
||||
vt = br_ ## cname ## _ctr_get_vtable(); \
|
||||
if (vt == NULL) { \
|
||||
printf("%-30s UNAVAILABLE\n", #Name); \
|
||||
fflush(stdout); \
|
||||
return; \
|
||||
} \
|
||||
for (i = 0; i < 10; i ++) { \
|
||||
vt->init(&ec.vtable, key, sizeof key); \
|
||||
vt->run(&ec.vtable, iv, 1, buf, sizeof buf); \
|
||||
|
|
@ -206,6 +216,23 @@ SPEED_HASH(SHA-1, sha1)
|
|||
SPEED_HASH(SHA-256, sha256)
|
||||
SPEED_HASH(SHA-512, sha512)
|
||||
|
||||
/*
|
||||
* There are no vtable selection functions for the portable implementations,
|
||||
* so we define some custom macros.
|
||||
*/
|
||||
#define br_aes_big_cbcenc_get_vtable() (&br_aes_big_cbcenc_vtable)
|
||||
#define br_aes_big_cbcdec_get_vtable() (&br_aes_big_cbcdec_vtable)
|
||||
#define br_aes_big_ctr_get_vtable() (&br_aes_big_ctr_vtable)
|
||||
#define br_aes_small_cbcenc_get_vtable() (&br_aes_small_cbcenc_vtable)
|
||||
#define br_aes_small_cbcdec_get_vtable() (&br_aes_small_cbcdec_vtable)
|
||||
#define br_aes_small_ctr_get_vtable() (&br_aes_small_ctr_vtable)
|
||||
#define br_aes_ct_cbcenc_get_vtable() (&br_aes_ct_cbcenc_vtable)
|
||||
#define br_aes_ct_cbcdec_get_vtable() (&br_aes_ct_cbcdec_vtable)
|
||||
#define br_aes_ct_ctr_get_vtable() (&br_aes_ct_ctr_vtable)
|
||||
#define br_aes_ct64_cbcenc_get_vtable() (&br_aes_ct64_cbcenc_vtable)
|
||||
#define br_aes_ct64_cbcdec_get_vtable() (&br_aes_ct64_cbcdec_vtable)
|
||||
#define br_aes_ct64_ctr_get_vtable() (&br_aes_ct64_ctr_vtable)
|
||||
|
||||
#define SPEED_AES(iname) \
|
||||
SPEED_BLOCKCIPHER_CBC(AES-128 CBC encrypt (iname), aes128_ ## iname ## _cbcenc, aes_ ## iname, 16, enc) \
|
||||
SPEED_BLOCKCIPHER_CBC(AES-128 CBC decrypt (iname), aes128_ ## iname ## _cbcdec, aes_ ## iname, 16, dec) \
|
||||
|
|
@ -221,6 +248,12 @@ SPEED_AES(big)
|
|||
SPEED_AES(small)
|
||||
SPEED_AES(ct)
|
||||
SPEED_AES(ct64)
|
||||
SPEED_AES(x86ni)
|
||||
|
||||
#define br_des_tab_cbcenc_get_vtable() (&br_des_tab_cbcenc_vtable)
|
||||
#define br_des_tab_cbcdec_get_vtable() (&br_des_tab_cbcdec_vtable)
|
||||
#define br_des_ct_cbcenc_get_vtable() (&br_des_ct_cbcenc_vtable)
|
||||
#define br_des_ct_cbcdec_get_vtable() (&br_des_ct_cbcdec_vtable)
|
||||
|
||||
#define SPEED_DES(iname) \
|
||||
SPEED_BLOCKCIPHER_CBC(DES CBC encrypt (iname), des_ ## iname ## _cbcenc, des_ ## iname, 8, enc) \
|
||||
|
|
@ -287,6 +320,20 @@ test_speed_ghash_ctmul64(void)
|
|||
test_speed_ghash_inner("GHASH (ctmul64)", &br_ghash_ctmul64);
|
||||
}
|
||||
|
||||
static void
|
||||
test_speed_ghash_pclmul(void)
|
||||
{
|
||||
br_ghash gh;
|
||||
|
||||
gh = br_ghash_pclmul_get();
|
||||
if (gh == 0) {
|
||||
printf("%-30s UNAVAILABLE\n", "GHASH (pclmul)");
|
||||
fflush(stdout);
|
||||
} else {
|
||||
test_speed_ghash_inner("GHASH (pclmul)", gh);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
fake_chacha20(const void *key, const void *iv,
|
||||
uint32_t cc, void *data, size_t len)
|
||||
|
|
@ -1158,6 +1205,16 @@ static const struct {
|
|||
STU(aes192_ct64_ctr),
|
||||
STU(aes256_ct64_ctr),
|
||||
|
||||
STU(aes128_x86ni_cbcenc),
|
||||
STU(aes128_x86ni_cbcdec),
|
||||
STU(aes192_x86ni_cbcenc),
|
||||
STU(aes192_x86ni_cbcdec),
|
||||
STU(aes256_x86ni_cbcenc),
|
||||
STU(aes256_x86ni_cbcdec),
|
||||
STU(aes128_x86ni_ctr),
|
||||
STU(aes192_x86ni_ctr),
|
||||
STU(aes256_x86ni_ctr),
|
||||
|
||||
STU(des_tab_cbcenc),
|
||||
STU(des_tab_cbcdec),
|
||||
STU(3des_tab_cbcenc),
|
||||
|
|
@ -1173,6 +1230,7 @@ static const struct {
|
|||
STU(ghash_ctmul),
|
||||
STU(ghash_ctmul32),
|
||||
STU(ghash_ctmul64),
|
||||
STU(ghash_pclmul),
|
||||
|
||||
STU(poly1305_ctmul),
|
||||
STU(poly1305_ctmul32),
|
||||
|
|
|
|||
|
|
@ -1531,9 +1531,9 @@ run_test_case(test_case *tc)
|
|||
br_x509_minimal_set_hash(&ctx, id, hash_impls[u].impl);
|
||||
}
|
||||
}
|
||||
br_x509_minimal_set_rsa(&ctx, br_rsa_i31_pkcs1_vrfy);
|
||||
br_x509_minimal_set_rsa(&ctx, br_rsa_pkcs1_vrfy_get_default());
|
||||
br_x509_minimal_set_ecdsa(&ctx,
|
||||
&br_ec_prime_i31, br_ecdsa_i31_vrfy_asn1);
|
||||
br_ec_get_default(), br_ecdsa_vrfy_asn1_get_default());
|
||||
|
||||
/*
|
||||
* Set the validation date.
|
||||
|
|
@ -1819,9 +1819,9 @@ test_name_extraction(void)
|
|||
id = hash_impls[u].id;
|
||||
br_x509_minimal_set_hash(&ctx, id, hash_impls[u].impl);
|
||||
}
|
||||
br_x509_minimal_set_rsa(&ctx, br_rsa_i31_pkcs1_vrfy);
|
||||
br_x509_minimal_set_rsa(&ctx, br_rsa_pkcs1_vrfy_get_default());
|
||||
br_x509_minimal_set_ecdsa(&ctx,
|
||||
&br_ec_prime_i31, br_ecdsa_i31_vrfy_asn1);
|
||||
br_ec_get_default(), br_ecdsa_vrfy_asn1_get_default());
|
||||
string_to_time(DEFAULT_TIME, &days, &seconds);
|
||||
br_x509_minimal_set_time(&ctx, days, seconds);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue