mirror of
https://github.com/yuzu-mirror/mbedtls.git
synced 2026-04-20 22:05:15 +00:00
The test cases use the following MPI values:
0 1 fffe ffffffff 100000000 20000000000000 ffffffffffffffff
10000000000000000 1234567890abcdef0 fffffffffffffffffefefefefefefefe
100000000000000000000000000000000 1234567890abcdef01234567890abcdef0
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
1234567890abcdef01234567890abcdef01234567890abcdef01234567890abcdef0
4df72d07b4b71c8dacb6cffa954f8d88254b6277099308baf003fab73227f34029643b5a263f66e0d3c3fa297ef71755efd53b8fb6cb812c6bbf7bcf179298bd9947c4c8b14324140a2c0f5fad7958a69050a987a6096e9f055fb38edf0c5889eca4a0cfa99b45fbdeee4c696b328ddceae4723945901ec025076b12b
and the following scalars. The .data files include two sets of results (final
accumulator and carry) for the cases sizeof(mbedtls_mpi_uint) == 4 or 8.
0 3 fe ff ffff 10000 ffffffff 100000000 7f7f7f7f7f7f7f7f 8000000000000000
fffffffffffffffe
The lines in the .data file were generated by the following script
#!/usr/bin/env perl
#
# mpi-test-core-mla.pl - generate/run MPI tests in Perl for mbedtls_mpi_core_mla()
#
use strict;
use warnings;
use Math::BigInt;
use sort 'stable';
my @mla_mpis = qw(
0 1 fffe ffffffff 100000000 20000000000000 ffffffffffffffff
10000000000000000 1234567890abcdef0 fffffffffffffffffefefefefefefefe
100000000000000000000000000000000 1234567890abcdef01234567890abcdef0
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
1234567890abcdef01234567890abcdef01234567890abcdef01234567890abcdef0
4df72d07b4b71c8dacb6cffa954f8d88254b6277099308baf003fab73227f34029643b5a263f66e0d3c3fa297ef71755efd53b8fb6cb812c6bbf7bcf179298bd9947c4c8b14324140a2c0f5fad7958a69050a987a6096e9f055fb38edf0c5889eca4a0cfa99b45fbdeee4c696b328ddceae4723945901ec025076b12b
);
my @mla_scalars = qw(
0 3 fe ff ffff 10000 ffffffff 100000000 7f7f7f7f7f7f7f7f 8000000000000000
fffffffffffffffe
);
my @mla_full_mpis = qw(
0 1 3 f fe ff 100 ff00 fffe ffff 10000
fffffffe ffffffff 100000000 1f7f7f7f7f7f7f
8000000000000000 fefefefefefefefe fffffffffffffffe ffffffffffffffff
10000000000000000 1234567890abcdef0
fffffffffffffffffefefefefefefefe fffffffffffffffffffffffffffffffe ffffffffffffffffffffffffffffffff
100000000000000000000000000000000 1234567890abcdef01234567890abcdef0
fffffffffffffffffffffffffffffffffffffffffffffffffefefefefefefefe
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
10000000000000000000000000000000000000000000000000000000000000000
1234567890abcdef01234567890abcdef01234567890abcdef01234567890abcdef0
4df72d07b4b71c8dacb6cffa954f8d88254b6277099308baf003fab73227f34029643b5a263f66e0d3c3fa297ef71755efd53b8fb6cb812c6bbf7bcf179298bd9947c4c8b14324140a2c0f5fad7958a69050a987a6096e9f055fb38edf0c5889eca4a0cfa99b45fbdeee4c696b328ddceae4723945901ec025076b12b
);
my @mla_full_scalars = qw(
0 1 3 f fe ff 100 ff00 fffe ffff 10000
fffffffe ffffffff 100000000
8000000000000000 fefefefefefefefe fffffffffffffffe ffffffffffffffff
);
generate_tests();
sub generate_tests {
generate_mbedtls_mpi_core_mla();
}
sub generate_mbedtls_mpi_core_mla {
my $sub_name = (caller(0))[3]; # e.g. main::generate_mbedtls_mpi_sub_mpi
my ($ignore, $test_name) = split("main::generate_", $sub_name);
my @cases = ();
for my $ah (@mla_mpis) {
for my $bh (@mla_mpis) {
for my $ch (@mla_scalars) {
# a += b * c (c is scalar)
# a_len >= b_len. need carry out.
my $a = Math::BigInt->from_hex($ah);
my $b = Math::BigInt->from_hex($bh);
my $c = Math::BigInt->from_hex($ch);
my $max = ($a > $b) ? $a : $b;
my $bound4 = bound_mpi4($max);
my $bound8 = bound_mpi8($max);
my $r = $a + $b * $c;
my ($r4, $cy4) = ($r->copy(), 0);
my ($r8, $cy8) = ($r->copy(), 0);
($cy4, $r4) = $r4->bdiv($bound4);
($cy8, $r8) = $r8->bdiv($bound8);
my $rh4 = $r4->to_hex();
my $rh8 = $r8->to_hex();
my $cyh4 = $cy4->to_hex();
my $cyh8 = $cy8->to_hex();
# If the scalar c is too big for 1 x 4-byte MPI, we can only run this test on a system with 8-byte MPIs
my $depends = mpi4s($c) > 1 ? "MBEDTLS_HAVE_INT64" : "";
my $desc = "$test_name #NUMBER: 0x$ah + 0x$bh * 0x$ch = (0x$rh4, carry 0x$cyh4)/(0x$rh8, carry 0x$cyh8)EXPLAIN";
my $case = output($test_name, str($ah), str($bh), str($ch), str($rh4), str($cyh4), str($rh8), str($cyh8));
push(@cases, [$case, $desc, $depends]);
}
}
}
output_cases(" (for when sizeof(mbedtls_mpi_uint) == 4/8)", @cases);
}
sub output_cases {
my ($explain, @cases) = @_;
my $count = 1;
for my $c (@cases) {
my ($case, $desc, $dep) = @$c;
$desc =~ s/NUMBER/$count/; $count++;
if (defined($explain) && $desc =~ /EXPLAIN/) {
$desc =~ s/EXPLAIN/$explain/;
$explain = "";
}
my $depends = "";
$depends = "depends_on:$dep\n" if defined($dep) && length($dep);
print <<EOF;
$desc
$depends$case
EOF
}
}
# The first number (a power of 2) that won't fit in the number of MPIs
# needed for the given number
sub bound_mpi4 {
my $one = Math::BigInt->new(1); # blsft modifies caller
return $one->blsft(bits_mpi4($_[0]));
}
sub bound_mpi8 {
my $one = Math::BigInt->new(1); # blsft modifies caller
return $one->blsft(bits_mpi8($_[0]));
}
# How many bits (a multiple of 32) needed to store the specified number
# when using 4-byte MPIs
sub bits_mpi4 {
return 32 * mpi4s($_[0]);
}
# How many bits (a multiple of 64) needed to store the specified number
# when using 8-byte MPIs
sub bits_mpi8 {
return 64 * mpi8s($_[0]);
}
# How many 4-byte MPIs needed to store the specified number
sub mpi4s {
my ($n) = @_;
my $h = $n->to_hex();
return int((length($h) + 7) / 8);
}
# How many 8-byte MPIs needed to store the specified number
sub mpi8s {
my ($n) = @_;
my $h = $n->to_hex();
return int((length($h) + 15) / 16);
}
sub output {
#run_test(@_);
return join(":", @_);
}
sub str {
return '"' . $_[0] . '"';
}
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
|
||
|---|---|---|
| .. | ||
| helpers.function | ||
| host_test.function | ||
| main_test.function | ||
| test_suite_aes.cbc.data | ||
| test_suite_aes.cfb.data | ||
| test_suite_aes.ecb.data | ||
| test_suite_aes.function | ||
| test_suite_aes.ofb.data | ||
| test_suite_aes.rest.data | ||
| test_suite_aes.xts.data | ||
| test_suite_aria.data | ||
| test_suite_aria.function | ||
| test_suite_asn1parse.data | ||
| test_suite_asn1parse.function | ||
| test_suite_asn1write.data | ||
| test_suite_asn1write.function | ||
| test_suite_base64.data | ||
| test_suite_base64.function | ||
| test_suite_camellia.data | ||
| test_suite_camellia.function | ||
| test_suite_ccm.data | ||
| test_suite_ccm.function | ||
| test_suite_chacha20.data | ||
| test_suite_chacha20.function | ||
| test_suite_chachapoly.data | ||
| test_suite_chachapoly.function | ||
| test_suite_cipher.aes.data | ||
| test_suite_cipher.aria.data | ||
| test_suite_cipher.camellia.data | ||
| test_suite_cipher.ccm.data | ||
| test_suite_cipher.chacha20.data | ||
| test_suite_cipher.chachapoly.data | ||
| test_suite_cipher.des.data | ||
| test_suite_cipher.function | ||
| test_suite_cipher.gcm.data | ||
| test_suite_cipher.misc.data | ||
| test_suite_cipher.nist_kw.data | ||
| test_suite_cipher.null.data | ||
| test_suite_cipher.padding.data | ||
| test_suite_cmac.data | ||
| test_suite_cmac.function | ||
| test_suite_ctr_drbg.data | ||
| test_suite_ctr_drbg.function | ||
| test_suite_debug.data | ||
| test_suite_debug.function | ||
| test_suite_des.data | ||
| test_suite_des.function | ||
| test_suite_dhm.data | ||
| test_suite_dhm.function | ||
| test_suite_ecdh.data | ||
| test_suite_ecdh.function | ||
| test_suite_ecdsa.data | ||
| test_suite_ecdsa.function | ||
| test_suite_ecjpake.data | ||
| test_suite_ecjpake.function | ||
| test_suite_ecp.data | ||
| test_suite_ecp.function | ||
| test_suite_entropy.data | ||
| test_suite_entropy.function | ||
| test_suite_error.data | ||
| test_suite_error.function | ||
| test_suite_gcm.aes128_de.data | ||
| test_suite_gcm.aes128_en.data | ||
| test_suite_gcm.aes192_de.data | ||
| test_suite_gcm.aes192_en.data | ||
| test_suite_gcm.aes256_de.data | ||
| test_suite_gcm.aes256_en.data | ||
| test_suite_gcm.camellia.data | ||
| test_suite_gcm.function | ||
| test_suite_gcm.misc.data | ||
| test_suite_hkdf.data | ||
| test_suite_hkdf.function | ||
| test_suite_hmac_drbg.function | ||
| test_suite_hmac_drbg.misc.data | ||
| test_suite_hmac_drbg.no_reseed.data | ||
| test_suite_hmac_drbg.nopr.data | ||
| test_suite_hmac_drbg.pr.data | ||
| test_suite_md.data | ||
| test_suite_md.function | ||
| test_suite_mdx.data | ||
| test_suite_mdx.function | ||
| test_suite_memory_buffer_alloc.data | ||
| test_suite_memory_buffer_alloc.function | ||
| test_suite_mpi.data | ||
| test_suite_mpi.function | ||
| test_suite_mps.data | ||
| test_suite_mps.function | ||
| test_suite_net.data | ||
| test_suite_net.function | ||
| test_suite_nist_kw.data | ||
| test_suite_nist_kw.function | ||
| test_suite_oid.data | ||
| test_suite_oid.function | ||
| test_suite_pem.data | ||
| test_suite_pem.function | ||
| test_suite_pk.data | ||
| test_suite_pk.function | ||
| test_suite_pkcs1_v15.data | ||
| test_suite_pkcs1_v15.function | ||
| test_suite_pkcs1_v21.data | ||
| test_suite_pkcs1_v21.function | ||
| test_suite_pkcs5.data | ||
| test_suite_pkcs5.function | ||
| test_suite_pkcs12.data | ||
| test_suite_pkcs12.function | ||
| test_suite_pkparse.data | ||
| test_suite_pkparse.function | ||
| test_suite_pkwrite.data | ||
| test_suite_pkwrite.function | ||
| test_suite_poly1305.data | ||
| test_suite_poly1305.function | ||
| test_suite_psa_crypto.data | ||
| test_suite_psa_crypto.function | ||
| test_suite_psa_crypto_attributes.data | ||
| test_suite_psa_crypto_attributes.function | ||
| test_suite_psa_crypto_driver_wrappers.data | ||
| test_suite_psa_crypto_driver_wrappers.function | ||
| test_suite_psa_crypto_entropy.data | ||
| test_suite_psa_crypto_entropy.function | ||
| test_suite_psa_crypto_generate_key.function | ||
| test_suite_psa_crypto_hash.data | ||
| test_suite_psa_crypto_hash.function | ||
| test_suite_psa_crypto_init.data | ||
| test_suite_psa_crypto_init.function | ||
| test_suite_psa_crypto_metadata.data | ||
| test_suite_psa_crypto_metadata.function | ||
| test_suite_psa_crypto_not_supported.function | ||
| test_suite_psa_crypto_not_supported.misc.data | ||
| test_suite_psa_crypto_op_fail.function | ||
| test_suite_psa_crypto_op_fail.misc.data | ||
| test_suite_psa_crypto_persistent_key.data | ||
| test_suite_psa_crypto_persistent_key.function | ||
| test_suite_psa_crypto_se_driver_hal.data | ||
| test_suite_psa_crypto_se_driver_hal.function | ||
| test_suite_psa_crypto_se_driver_hal_mocks.data | ||
| test_suite_psa_crypto_se_driver_hal_mocks.function | ||
| test_suite_psa_crypto_slot_management.data | ||
| test_suite_psa_crypto_slot_management.function | ||
| test_suite_psa_crypto_storage_format.function | ||
| test_suite_psa_crypto_storage_format.misc.data | ||
| test_suite_psa_its.data | ||
| test_suite_psa_its.function | ||
| test_suite_random.data | ||
| test_suite_random.function | ||
| test_suite_rsa.data | ||
| test_suite_rsa.function | ||
| test_suite_shax.data | ||
| test_suite_shax.function | ||
| test_suite_ssl.data | ||
| test_suite_ssl.function | ||
| test_suite_timing.data | ||
| test_suite_timing.function | ||
| test_suite_version.data | ||
| test_suite_version.function | ||
| test_suite_x509parse.data | ||
| test_suite_x509parse.function | ||
| test_suite_x509write.data | ||
| test_suite_x509write.function | ||