New upstream version 0.061
gregor herrmann
5 years ago
0 | 0 | Changes for CryptX |
1 | ||
2 | 0.061 2018-06-07 | |
3 | - bundled libtommath update (+stdint.h workaround) | |
4 | - bundled libtomcrypt update (+necessary adaptation) | |
5 | - fix #43 HP-UX 11.11 C-ANSI-C has no stdint.h | |
6 | - fix #44 Anonymous unions are GNU and C11 (troubles with HP C/aC++, HP-UX 11.31/IA64) | |
1 | 7 | |
2 | 8 | 0.060 2018-05-01 |
3 | 9 | - bundled libtomcrypt update |
254 | 254 | src/ltc/headers/tomcrypt_misc.h |
255 | 255 | src/ltc/headers/tomcrypt_pk.h |
256 | 256 | src/ltc/headers/tomcrypt_pkcs.h |
257 | src/ltc/headers/tomcrypt_private.h | |
257 | 258 | src/ltc/headers/tomcrypt_prng.h |
258 | 259 | src/ltc/mac/blake2/blake2bmac.c |
259 | 260 | src/ltc/mac/blake2/blake2bmac_file.c |
482 | 483 | src/ltc/pk/ecc/ecc_free.c |
483 | 484 | src/ltc/pk/ecc/ecc_get_curve.c |
484 | 485 | src/ltc/pk/ecc/ecc_get_key.c |
486 | src/ltc/pk/ecc/ecc_get_oid_str.c | |
485 | 487 | src/ltc/pk/ecc/ecc_get_size.c |
486 | 488 | src/ltc/pk/ecc/ecc_import.c |
487 | 489 | src/ltc/pk/ecc/ecc_import_openssl.c |
551 | 553 | src/ltc/stream/salsa20/salsa20_ivctr64.c |
552 | 554 | src/ltc/stream/salsa20/salsa20_keystream.c |
553 | 555 | src/ltc/stream/salsa20/salsa20_setup.c |
556 | src/ltc/stream/salsa20/xsalsa20_setup.c | |
554 | 557 | src/ltc/stream/sober128/sober128_stream.c |
555 | 558 | src/ltc/stream/sober128/sober128tab.c |
556 | 559 | src/ltc/stream/sosemanuk/sosemanuk.c |
595 | 598 | src/ltm/bn_mp_gcd.c |
596 | 599 | src/ltm/bn_mp_get_int.c |
597 | 600 | src/ltm/bn_mp_get_long.c |
598 | src/ltm/bn_mp_get_long_long.c | |
599 | 601 | src/ltm/bn_mp_grow.c |
600 | 602 | src/ltm/bn_mp_import.c |
601 | 603 | src/ltm/bn_mp_init.c |
652 | 654 | src/ltm/bn_mp_set.c |
653 | 655 | src/ltm/bn_mp_set_int.c |
654 | 656 | src/ltm/bn_mp_set_long.c |
655 | src/ltm/bn_mp_set_long_long.c | |
656 | 657 | src/ltm/bn_mp_shrink.c |
657 | 658 | src/ltm/bn_mp_signed_bin_size.c |
658 | 659 | src/ltm/bn_mp_sqr.c |
44 | 44 | "url" : "https://github.com/DCIT/perl-CryptX" |
45 | 45 | } |
46 | 46 | }, |
47 | "version" : "0.060", | |
47 | "version" : "0.061", | |
48 | 48 | "x_serialization_backend" : "JSON::PP version 2.94" |
49 | 49 | } |
21 | 21 | resources: |
22 | 22 | bugtracker: https://github.com/DCIT/perl-CryptX/issues |
23 | 23 | repository: https://github.com/DCIT/perl-CryptX |
24 | version: '0.060' | |
24 | version: '0.061' | |
25 | 25 | x_serialization_backend: 'CPAN::Meta::YAML version 0.018' |
49 | 49 | if (self->key.type != -1) { ecc_free(&self->key); self->key.type = -1; } |
50 | 50 | rv = ecc_import_openssl(data, (unsigned long)data_len, &self->key); |
51 | 51 | if (rv != CRYPT_OK) croak("FATAL: ecc_import_openssl failed: %s", error_to_string(rv)); |
52 | XPUSHs(ST(0)); /* return self */ | |
53 | } | |
54 | ||
55 | void | |
56 | _import_old(Crypt::PK::ECC self, SV * key_data) | |
57 | PPCODE: | |
58 | { | |
59 | int rv; | |
60 | unsigned char *data=NULL; | |
61 | STRLEN data_len=0; | |
62 | ||
63 | data = (unsigned char *)SvPVbyte(key_data, data_len); | |
64 | if (self->key.type != -1) { ecc_free(&self->key); self->key.type = -1; } | |
65 | rv = ecc_import(data, (unsigned long)data_len, &self->key); | |
66 | if (rv != CRYPT_OK) croak("FATAL: ecc_import failed: %s", error_to_string(rv)); | |
52 | 67 | XPUSHs(ST(0)); /* return self */ |
53 | 68 | } |
54 | 69 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( ccm_encrypt_authenticate ccm_decrypt_verify )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( eax_encrypt_authenticate eax_decrypt_verify )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( gcm_encrypt_authenticate gcm_decrypt_verify )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( ocb_encrypt_authenticate ocb_decrypt_verify )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | ### not used |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use base qw(Crypt::Checksum Exporter); |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use base qw(Crypt::Checksum Exporter); |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( crc32_data crc32_data_hex crc32_data_int crc32_file crc32_file_hex crc32_file_int )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw/ adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Cipher); |
9 | 9 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use Carp; |
7 | 7 | $Carp::Internal{(__PACKAGE__)}++; |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2b_160 blake2b_160_hex blake2b_160_b64 blake2b_160_b64u blake2b_160_file blake2b_160_file_hex blake2b_160_file_b64 blake2b_160_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2b_256 blake2b_256_hex blake2b_256_b64 blake2b_256_b64u blake2b_256_file blake2b_256_file_hex blake2b_256_file_b64 blake2b_256_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2b_384 blake2b_384_hex blake2b_384_b64 blake2b_384_b64u blake2b_384_file blake2b_384_file_hex blake2b_384_file_b64 blake2b_384_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2b_512 blake2b_512_hex blake2b_512_b64 blake2b_512_b64u blake2b_512_file blake2b_512_file_hex blake2b_512_file_b64 blake2b_512_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2s_128 blake2s_128_hex blake2s_128_b64 blake2s_128_b64u blake2s_128_file blake2s_128_file_hex blake2s_128_file_b64 blake2s_128_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2s_160 blake2s_160_hex blake2s_160_b64 blake2s_160_b64u blake2s_160_file blake2s_160_file_hex blake2s_160_file_b64 blake2s_160_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2s_224 blake2s_224_hex blake2s_224_b64 blake2s_224_b64u blake2s_224_file blake2s_224_file_hex blake2s_224_file_b64 blake2s_224_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2s_256 blake2s_256_hex blake2s_256_b64 blake2s_256_b64u blake2s_256_file blake2s_256_file_hex blake2s_256_file_b64 blake2s_256_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( chaes chaes_hex chaes_b64 chaes_b64u chaes_file chaes_file_hex chaes_file_b64 chaes_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( keccak224 keccak224_hex keccak224_b64 keccak224_b64u keccak224_file keccak224_file_hex keccak224_file_b64 keccak224_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( keccak256 keccak256_hex keccak256_b64 keccak256_b64u keccak256_file keccak256_file_hex keccak256_file_b64 keccak256_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( keccak384 keccak384_hex keccak384_b64 keccak384_b64u keccak384_file keccak384_file_hex keccak384_file_b64 keccak384_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( keccak512 keccak512_hex keccak512_b64 keccak512_b64u keccak512_file keccak512_file_hex keccak512_file_b64 keccak512_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( md2 md2_hex md2_b64 md2_b64u md2_file md2_file_hex md2_file_b64 md2_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( md4 md4_hex md4_b64 md4_b64u md4_file md4_file_hex md4_file_b64 md4_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( md5 md5_hex md5_b64 md5_b64u md5_file md5_file_hex md5_file_b64 md5_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( ripemd128 ripemd128_hex ripemd128_b64 ripemd128_b64u ripemd128_file ripemd128_file_hex ripemd128_file_b64 ripemd128_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( ripemd160 ripemd160_hex ripemd160_b64 ripemd160_b64u ripemd160_file ripemd160_file_hex ripemd160_file_b64 ripemd160_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( ripemd256 ripemd256_hex ripemd256_b64 ripemd256_b64u ripemd256_file ripemd256_file_hex ripemd256_file_b64 ripemd256_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( ripemd320 ripemd320_hex ripemd320_b64 ripemd320_b64u ripemd320_file ripemd320_file_hex ripemd320_file_b64 ripemd320_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha1 sha1_hex sha1_b64 sha1_b64u sha1_file sha1_file_hex sha1_file_b64 sha1_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha224 sha224_hex sha224_b64 sha224_b64u sha224_file sha224_file_hex sha224_file_b64 sha224_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha256 sha256_hex sha256_b64 sha256_b64u sha256_file sha256_file_hex sha256_file_b64 sha256_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha384 sha384_hex sha384_b64 sha384_b64u sha384_file sha384_file_hex sha384_file_b64 sha384_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha3_224 sha3_224_hex sha3_224_b64 sha3_224_b64u sha3_224_file sha3_224_file_hex sha3_224_file_b64 sha3_224_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha3_256 sha3_256_hex sha3_256_b64 sha3_256_b64u sha3_256_file sha3_256_file_hex sha3_256_file_b64 sha3_256_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha3_384 sha3_384_hex sha3_384_b64 sha3_384_b64u sha3_384_file sha3_384_file_hex sha3_384_file_b64 sha3_384_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha3_512 sha3_512_hex sha3_512_b64 sha3_512_b64u sha3_512_file sha3_512_file_hex sha3_512_file_b64 sha3_512_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha512 sha512_hex sha512_b64 sha512_b64u sha512_file sha512_file_hex sha512_file_b64 sha512_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha512_224 sha512_224_hex sha512_224_b64 sha512_224_b64u sha512_224_file sha512_224_file_hex sha512_224_file_b64 sha512_224_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( sha512_256 sha512_256_hex sha512_256_b64 sha512_256_b64u sha512_256_file sha512_256_file_hex sha512_256_file_b64 sha512_256_file_b64u )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use Carp; |
7 | 7 | $Carp::Internal{(__PACKAGE__)}++; |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( tiger192 tiger192_hex tiger192_b64 tiger192_b64u tiger192_file tiger192_file_hex tiger192_file_b64 tiger192_file_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Digest Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( whirlpool whirlpool_hex whirlpool_b64 whirlpool_b64u whirlpool_file whirlpool_file_hex whirlpool_file_b64 whirlpool_file_b64u )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( digest_data digest_data_hex digest_data_b64 digest_data_b64u digest_file digest_file_hex digest_file_b64 digest_file_b64u )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw(pbkdf1 pbkdf2 hkdf hkdf_expand hkdf_extract)] ); |
21 | 21 | Crypt::KeyDerivation - PBKDF1, PBKDF2 and HKDF key derivation functions |
22 | 22 | |
23 | 23 | =head1 SYNOPSIS |
24 | ||
25 | use Crypt::KeyDerivation ':all'; | |
24 | 26 | |
25 | 27 | ### PBKDF1/2 |
26 | 28 | $derived_key1 = pbkdf1($password, $salt, $iteration_count, $hash_name, $len); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2b blake2b_hex blake2b_b64 blake2b_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( blake2s blake2s_hex blake2s_b64 blake2s_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( f9 f9_hex f9_b64 f9_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( hmac hmac_hex hmac_b64 hmac_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( omac omac_hex omac_b64 omac_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( pmac pmac_hex pmac_b64 pmac_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( pelican pelican_hex pelican_b64 pelican_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( poly1305 poly1305_hex poly1305_b64 poly1305_b64u )] ); |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use base qw(Crypt::Mac Exporter); |
9 | 9 | our %EXPORT_TAGS = ( all => [qw( xcbc xcbc_hex xcbc_b64 xcbc_b64u )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use Carp; |
7 | 7 | $Carp::Internal{(__PACKAGE__)}++; |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import'; |
7 | 7 | use Carp 'croak'; |
215 | 215 | my ($cipher, undef, $klen, $mode) = $cipher_name =~ /^(AES|CAMELLIA|DES|DES-EDE3|SEED)(-(\d+))?-(CBC|CFB|ECB|OFB)$/i; |
216 | 216 | croak "FATAL: unsupported cipher '$cipher_name'" unless $cipher && $mode; |
217 | 217 | $cipher = $trans{$cipher} || $cipher; |
218 | $klen = 192 if $cipher eq 'DES_EDE'; | |
219 | $klen = 64 if $cipher eq 'DES'; | |
220 | $klen = 128 if $cipher eq 'SEED'; | |
218 | 221 | $klen = $klen ? int($klen/8) : Crypt::Cipher::min_keysize($cipher); |
219 | 222 | my $ilen = Crypt::Cipher::blocksize($cipher); |
220 | 223 | croak "FATAL: unsupported cipher '$cipher_name'" unless $klen && $ilen; |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use Crypt::Cipher; |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use Crypt::Cipher; |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use Crypt::Cipher; |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use Crypt::Cipher; |
9 | 9 |
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | our $VERSION = '0.060'; | |
6 | our $VERSION = '0.061'; | |
7 | 7 | |
8 | 8 | use Crypt::Cipher; |
9 | 9 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | ### not used |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( dh_shared_secret )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( dsa_encrypt dsa_decrypt dsa_sign_message dsa_verify_message dsa_sign_hash dsa_verify_hash )] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw( ecc_encrypt ecc_decrypt ecc_sign_message ecc_verify_message ecc_sign_hash ecc_verify_hash ecc_shared_secret )] ); |
215 | 215 | |
216 | 216 | if ($data =~ /-----BEGIN (EC PRIVATE|EC PUBLIC|PUBLIC) KEY-----(.*?)-----END/sg) { |
217 | 217 | $data = pem_to_der($data, $password); |
218 | return $self->_import($data); | |
218 | my $rv = eval { $self->_import($data) } || eval { $self->_import_old($data) }; | |
219 | return $rv if $rv; | |
219 | 220 | } |
220 | 221 | elsif ($data =~ /-----BEGIN PRIVATE KEY-----(.*?)-----END/sg) { |
221 | 222 | $data = pem_to_der($data, $password); |
252 | 253 | return $self->import_key_raw($pubkey, "$2") if $pubkey && $typ =~ /^ecdsa-(.+?)-(.*)$/; |
253 | 254 | } |
254 | 255 | else { |
255 | my $rv = eval { $self->_import($data) } || eval { $self->_import_pkcs8($data, $password) } || eval { $self->_import_x509($data) }; | |
256 | my $rv = eval { $self->_import($data) } || | |
257 | eval { $self->_import_old($data) } || | |
258 | eval { $self->_import_pkcs8($data, $password) } || | |
259 | eval { $self->_import_x509($data) }; | |
256 | 260 | return $rv if $rv; |
257 | 261 | } |
258 | 262 | croak "FATAL: invalid or unsupported EC key format"; |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw(rsa_encrypt rsa_decrypt rsa_sign_message rsa_verify_message rsa_sign_hash rsa_verify_hash)] ); |
9 | 9 | our @EXPORT = qw(); |
10 | 10 | |
11 | 11 | use Carp; |
12 | $Carp::Internal{(__PACKAGE__)}++; | |
12 | 13 | use CryptX; |
13 | 14 | use Crypt::Digest qw(digest_data digest_data_b64u); |
14 | 15 | use Crypt::Misc qw(read_rawfile encode_b64u decode_b64u encode_b64 decode_b64 pem_to_der der_to_pem); |
21 | 22 | |
22 | 23 | sub export_key_pem { |
23 | 24 | my ($self, $type, $password, $cipher) = @_; |
25 | local $SIG{__DIE__} = \&CryptX::_croak; | |
24 | 26 | my $key = $self->export_key_der($type||''); |
25 | 27 | return unless $key; |
26 | 28 | |
37 | 39 | |
38 | 40 | sub export_key_jwk { |
39 | 41 | my ($self, $type, $wanthash) = @_; |
42 | local $SIG{__DIE__} = \&CryptX::_croak; | |
40 | 43 | my $kh = $self->key2hash; |
41 | 44 | if ($type eq 'private') { |
42 | 45 | return unless $kh->{N} && $kh->{e} && $kh->{d} && $kh->{p} && $kh->{q} && $kh->{dP} && $kh->{dQ} && $kh->{qP}; |
72 | 75 | |
73 | 76 | sub export_key_jwk_thumbprint { |
74 | 77 | my ($self, $hash_name) = @_; |
78 | local $SIG{__DIE__} = \&CryptX::_croak; | |
75 | 79 | $hash_name ||= 'SHA256'; |
76 | 80 | my $h = $self->export_key_jwk('public', 1); |
77 | 81 | my $json = CryptX::_encode_json({kty=>$h->{kty}, n=>$h->{n}, e=>$h->{e}}); |
80 | 84 | |
81 | 85 | sub import_key { |
82 | 86 | my ($self, $key, $password) = @_; |
87 | local $SIG{__DIE__} = \&CryptX::_croak; | |
83 | 88 | croak "FATAL: undefined key" unless $key; |
84 | 89 | |
85 | 90 | # special case |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use Carp; |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use base qw(Crypt::PRNG Exporter); |
7 | 7 | our %EXPORT_TAGS = ( all => [qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u random_string random_string_from rand irand)] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use base qw(Crypt::PRNG Exporter); |
7 | 7 | our %EXPORT_TAGS = ( all => [qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u random_string random_string_from rand irand)] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use base qw(Crypt::PRNG Exporter); |
7 | 7 | our %EXPORT_TAGS = ( all => [qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u random_string random_string_from rand irand)] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use base qw(Crypt::PRNG Exporter); |
7 | 7 | our %EXPORT_TAGS = ( all => [qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u random_string random_string_from rand irand)] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use base qw(Crypt::PRNG Exporter); |
7 | 7 | our %EXPORT_TAGS = ( all => [qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u random_string random_string_from rand irand)] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import'; |
7 | 7 | our %EXPORT_TAGS = ( all => [qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u random_string random_string_from rand irand)] ); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use CryptX; |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use CryptX; |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use CryptX; |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use CryptX; |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use CryptX; |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use CryptX; |
7 | 7 |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings ; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | require XSLoader; |
7 | 7 | XSLoader::load('CryptX', $VERSION); |
1 | 1 | |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | our $VERSION = '0.060'; | |
4 | our $VERSION = '0.061'; | |
5 | 5 | |
6 | 6 | use CryptX; |
7 | 7 |
102 | 102 | ltc/pk/dsa/dsa_verify_hash.o ltc/pk/dsa/dsa_verify_key.o ltc/pk/ecc/ecc.o ltc/pk/ecc/ecc_ansi_x963_export.o \ |
103 | 103 | ltc/pk/ecc/ecc_ansi_x963_import.o ltc/pk/ecc/ecc_decrypt_key.o ltc/pk/ecc/ecc_encrypt_key.o \ |
104 | 104 | ltc/pk/ecc/ecc_export.o ltc/pk/ecc/ecc_export_openssl.o ltc/pk/ecc/ecc_free.o ltc/pk/ecc/ecc_get_curve.o \ |
105 | ltc/pk/ecc/ecc_get_key.o ltc/pk/ecc/ecc_get_size.o ltc/pk/ecc/ecc_import.o ltc/pk/ecc/ecc_import_openssl.o \ | |
106 | ltc/pk/ecc/ecc_import_pkcs8.o ltc/pk/ecc/ecc_import_x509.o ltc/pk/ecc/ecc_make_key.o \ | |
107 | ltc/pk/ecc/ecc_set_dp.o ltc/pk/ecc/ecc_set_dp_internal.o ltc/pk/ecc/ecc_set_key.o \ | |
108 | ltc/pk/ecc/ecc_shared_secret.o ltc/pk/ecc/ecc_sign_hash.o ltc/pk/ecc/ecc_sizes.o \ | |
109 | ltc/pk/ecc/ecc_verify_hash.o ltc/pk/ecc/ltc_ecc_export_point.o ltc/pk/ecc/ltc_ecc_import_point.o \ | |
110 | ltc/pk/ecc/ltc_ecc_is_point.o ltc/pk/ecc/ltc_ecc_is_point_at_infinity.o ltc/pk/ecc/ltc_ecc_map.o \ | |
111 | ltc/pk/ecc/ltc_ecc_mul2add.o ltc/pk/ecc/ltc_ecc_mulmod.o ltc/pk/ecc/ltc_ecc_mulmod_timing.o \ | |
112 | ltc/pk/ecc/ltc_ecc_points.o ltc/pk/ecc/ltc_ecc_projective_add_point.o ltc/pk/ecc/ltc_ecc_projective_dbl_point.o \ | |
113 | ltc/pk/ecc/ltc_ecc_verify_key.o ltc/pk/pkcs1/pkcs_1_i2osp.o ltc/pk/pkcs1/pkcs_1_mgf1.o \ | |
114 | ltc/pk/pkcs1/pkcs_1_oaep_decode.o ltc/pk/pkcs1/pkcs_1_oaep_encode.o ltc/pk/pkcs1/pkcs_1_os2ip.o \ | |
115 | ltc/pk/pkcs1/pkcs_1_pss_decode.o ltc/pk/pkcs1/pkcs_1_pss_encode.o ltc/pk/pkcs1/pkcs_1_v1_5_decode.o \ | |
116 | ltc/pk/pkcs1/pkcs_1_v1_5_encode.o ltc/pk/rsa/rsa_decrypt_key.o ltc/pk/rsa/rsa_encrypt_key.o \ | |
117 | ltc/pk/rsa/rsa_export.o ltc/pk/rsa/rsa_exptmod.o ltc/pk/rsa/rsa_free.o ltc/pk/rsa/rsa_get_size.o \ | |
118 | ltc/pk/rsa/rsa_import.o ltc/pk/rsa/rsa_import_pkcs8.o ltc/pk/rsa/rsa_import_x509.o \ | |
105 | ltc/pk/ecc/ecc_get_key.o ltc/pk/ecc/ecc_get_oid_str.o ltc/pk/ecc/ecc_get_size.o ltc/pk/ecc/ecc_import.o \ | |
106 | ltc/pk/ecc/ecc_import_openssl.o ltc/pk/ecc/ecc_import_pkcs8.o ltc/pk/ecc/ecc_import_x509.o \ | |
107 | ltc/pk/ecc/ecc_make_key.o ltc/pk/ecc/ecc_set_dp.o ltc/pk/ecc/ecc_set_dp_internal.o \ | |
108 | ltc/pk/ecc/ecc_set_key.o ltc/pk/ecc/ecc_shared_secret.o ltc/pk/ecc/ecc_sign_hash.o \ | |
109 | ltc/pk/ecc/ecc_sizes.o ltc/pk/ecc/ecc_verify_hash.o ltc/pk/ecc/ltc_ecc_export_point.o \ | |
110 | ltc/pk/ecc/ltc_ecc_import_point.o ltc/pk/ecc/ltc_ecc_is_point.o ltc/pk/ecc/ltc_ecc_is_point_at_infinity.o \ | |
111 | ltc/pk/ecc/ltc_ecc_map.o ltc/pk/ecc/ltc_ecc_mul2add.o ltc/pk/ecc/ltc_ecc_mulmod.o \ | |
112 | ltc/pk/ecc/ltc_ecc_mulmod_timing.o ltc/pk/ecc/ltc_ecc_points.o ltc/pk/ecc/ltc_ecc_projective_add_point.o \ | |
113 | ltc/pk/ecc/ltc_ecc_projective_dbl_point.o ltc/pk/ecc/ltc_ecc_verify_key.o ltc/pk/pkcs1/pkcs_1_i2osp.o \ | |
114 | ltc/pk/pkcs1/pkcs_1_mgf1.o ltc/pk/pkcs1/pkcs_1_oaep_decode.o ltc/pk/pkcs1/pkcs_1_oaep_encode.o \ | |
115 | ltc/pk/pkcs1/pkcs_1_os2ip.o ltc/pk/pkcs1/pkcs_1_pss_decode.o ltc/pk/pkcs1/pkcs_1_pss_encode.o \ | |
116 | ltc/pk/pkcs1/pkcs_1_v1_5_decode.o ltc/pk/pkcs1/pkcs_1_v1_5_encode.o ltc/pk/rsa/rsa_decrypt_key.o \ | |
117 | ltc/pk/rsa/rsa_encrypt_key.o ltc/pk/rsa/rsa_export.o ltc/pk/rsa/rsa_exptmod.o ltc/pk/rsa/rsa_free.o \ | |
118 | ltc/pk/rsa/rsa_get_size.o ltc/pk/rsa/rsa_import.o ltc/pk/rsa/rsa_import_pkcs8.o ltc/pk/rsa/rsa_import_x509.o \ | |
119 | 119 | ltc/pk/rsa/rsa_make_key.o ltc/pk/rsa/rsa_set.o ltc/pk/rsa/rsa_sign_hash.o ltc/pk/rsa/rsa_sign_saltlen_get.o \ |
120 | 120 | ltc/pk/rsa/rsa_verify_hash.o ltc/prngs/chacha20.o ltc/prngs/fortuna.o ltc/prngs/rc4.o \ |
121 | 121 | ltc/prngs/rng_get_bytes.o ltc/prngs/rng_make_prng.o ltc/prngs/sober128.o ltc/prngs/sprng.o \ |
123 | 123 | ltc/stream/chacha/chacha_ivctr32.o ltc/stream/chacha/chacha_ivctr64.o ltc/stream/chacha/chacha_keystream.o \ |
124 | 124 | ltc/stream/chacha/chacha_setup.o ltc/stream/rabbit/rabbit.o ltc/stream/rc4/rc4_stream.o \ |
125 | 125 | ltc/stream/salsa20/salsa20_crypt.o ltc/stream/salsa20/salsa20_done.o ltc/stream/salsa20/salsa20_ivctr64.o \ |
126 | ltc/stream/salsa20/salsa20_keystream.o ltc/stream/salsa20/salsa20_setup.o ltc/stream/sober128/sober128_stream.o \ | |
127 | ltc/stream/sosemanuk/sosemanuk.o ltm/bncore.o ltm/bn_error.o ltm/bn_fast_mp_invmod.o \ | |
128 | ltm/bn_fast_mp_montgomery_reduce.o ltm/bn_fast_s_mp_mul_digs.o ltm/bn_fast_s_mp_mul_high_digs.o \ | |
129 | ltm/bn_fast_s_mp_sqr.o ltm/bn_mp_2expt.o ltm/bn_mp_abs.o ltm/bn_mp_add.o ltm/bn_mp_addmod.o \ | |
130 | ltm/bn_mp_add_d.o ltm/bn_mp_and.o ltm/bn_mp_clamp.o ltm/bn_mp_clear.o ltm/bn_mp_clear_multi.o \ | |
131 | ltm/bn_mp_cmp.o ltm/bn_mp_cmp_d.o ltm/bn_mp_cmp_mag.o ltm/bn_mp_cnt_lsb.o ltm/bn_mp_copy.o \ | |
132 | ltm/bn_mp_count_bits.o ltm/bn_mp_div.o ltm/bn_mp_div_2.o ltm/bn_mp_div_2d.o ltm/bn_mp_div_3.o \ | |
133 | ltm/bn_mp_div_d.o ltm/bn_mp_dr_is_modulus.o ltm/bn_mp_dr_reduce.o ltm/bn_mp_dr_setup.o \ | |
134 | ltm/bn_mp_exch.o ltm/bn_mp_export.o ltm/bn_mp_exptmod.o ltm/bn_mp_exptmod_fast.o \ | |
135 | ltm/bn_mp_expt_d.o ltm/bn_mp_expt_d_ex.o ltm/bn_mp_exteuclid.o ltm/bn_mp_fread.o \ | |
136 | ltm/bn_mp_fwrite.o ltm/bn_mp_gcd.o ltm/bn_mp_get_int.o ltm/bn_mp_get_long.o ltm/bn_mp_get_long_long.o \ | |
126 | ltc/stream/salsa20/salsa20_keystream.o ltc/stream/salsa20/salsa20_setup.o ltc/stream/salsa20/xsalsa20_setup.o \ | |
127 | ltc/stream/sober128/sober128_stream.o ltc/stream/sosemanuk/sosemanuk.o ltm/bncore.o \ | |
128 | ltm/bn_error.o ltm/bn_fast_mp_invmod.o ltm/bn_fast_mp_montgomery_reduce.o ltm/bn_fast_s_mp_mul_digs.o \ | |
129 | ltm/bn_fast_s_mp_mul_high_digs.o ltm/bn_fast_s_mp_sqr.o ltm/bn_mp_2expt.o ltm/bn_mp_abs.o \ | |
130 | ltm/bn_mp_add.o ltm/bn_mp_addmod.o ltm/bn_mp_add_d.o ltm/bn_mp_and.o ltm/bn_mp_clamp.o \ | |
131 | ltm/bn_mp_clear.o ltm/bn_mp_clear_multi.o ltm/bn_mp_cmp.o ltm/bn_mp_cmp_d.o ltm/bn_mp_cmp_mag.o \ | |
132 | ltm/bn_mp_cnt_lsb.o ltm/bn_mp_copy.o ltm/bn_mp_count_bits.o ltm/bn_mp_div.o ltm/bn_mp_div_2.o \ | |
133 | ltm/bn_mp_div_2d.o ltm/bn_mp_div_3.o ltm/bn_mp_div_d.o ltm/bn_mp_dr_is_modulus.o \ | |
134 | ltm/bn_mp_dr_reduce.o ltm/bn_mp_dr_setup.o ltm/bn_mp_exch.o ltm/bn_mp_export.o ltm/bn_mp_exptmod.o \ | |
135 | ltm/bn_mp_exptmod_fast.o ltm/bn_mp_expt_d.o ltm/bn_mp_expt_d_ex.o ltm/bn_mp_exteuclid.o \ | |
136 | ltm/bn_mp_fread.o ltm/bn_mp_fwrite.o ltm/bn_mp_gcd.o ltm/bn_mp_get_int.o ltm/bn_mp_get_long.o \ | |
137 | 137 | ltm/bn_mp_grow.o ltm/bn_mp_import.o ltm/bn_mp_init.o ltm/bn_mp_init_copy.o ltm/bn_mp_init_multi.o \ |
138 | 138 | ltm/bn_mp_init_set.o ltm/bn_mp_init_set_int.o ltm/bn_mp_init_size.o ltm/bn_mp_invmod.o \ |
139 | 139 | ltm/bn_mp_invmod_slow.o ltm/bn_mp_is_square.o ltm/bn_mp_jacobi.o ltm/bn_mp_karatsuba_mul.o \ |
148 | 148 | ltm/bn_mp_reduce.o ltm/bn_mp_reduce_2k.o ltm/bn_mp_reduce_2k_l.o ltm/bn_mp_reduce_2k_setup.o \ |
149 | 149 | ltm/bn_mp_reduce_2k_setup_l.o ltm/bn_mp_reduce_is_2k.o ltm/bn_mp_reduce_is_2k_l.o \ |
150 | 150 | ltm/bn_mp_reduce_setup.o ltm/bn_mp_rshd.o ltm/bn_mp_set.o ltm/bn_mp_set_int.o ltm/bn_mp_set_long.o \ |
151 | ltm/bn_mp_set_long_long.o ltm/bn_mp_shrink.o ltm/bn_mp_signed_bin_size.o ltm/bn_mp_sqr.o \ | |
152 | ltm/bn_mp_sqrmod.o ltm/bn_mp_sqrt.o ltm/bn_mp_sqrtmod_prime.o ltm/bn_mp_sub.o ltm/bn_mp_submod.o \ | |
153 | ltm/bn_mp_sub_d.o ltm/bn_mp_toom_mul.o ltm/bn_mp_toom_sqr.o ltm/bn_mp_toradix.o ltm/bn_mp_toradix_n.o \ | |
151 | ltm/bn_mp_shrink.o ltm/bn_mp_signed_bin_size.o ltm/bn_mp_sqr.o ltm/bn_mp_sqrmod.o \ | |
152 | ltm/bn_mp_sqrt.o ltm/bn_mp_sqrtmod_prime.o ltm/bn_mp_sub.o ltm/bn_mp_submod.o ltm/bn_mp_sub_d.o \ | |
153 | ltm/bn_mp_toom_mul.o ltm/bn_mp_toom_sqr.o ltm/bn_mp_toradix.o ltm/bn_mp_toradix_n.o \ | |
154 | 154 | ltm/bn_mp_to_signed_bin.o ltm/bn_mp_to_signed_bin_n.o ltm/bn_mp_to_unsigned_bin.o \ |
155 | 155 | ltm/bn_mp_to_unsigned_bin_n.o ltm/bn_mp_unsigned_bin_size.o ltm/bn_mp_xor.o ltm/bn_mp_zero.o \ |
156 | 156 | ltm/bn_prime_tab.o ltm/bn_reverse.o ltm/bn_s_mp_add.o ltm/bn_s_mp_exptmod.o ltm/bn_s_mp_mul_digs.o \ |
109 | 109 | ltc/pk/dsa/dsa_verify_key.obj ltc/pk/ecc/ecc.obj ltc/pk/ecc/ecc_ansi_x963_export.obj \ |
110 | 110 | ltc/pk/ecc/ecc_ansi_x963_import.obj ltc/pk/ecc/ecc_decrypt_key.obj ltc/pk/ecc/ecc_encrypt_key.obj \ |
111 | 111 | ltc/pk/ecc/ecc_export.obj ltc/pk/ecc/ecc_export_openssl.obj ltc/pk/ecc/ecc_free.obj \ |
112 | ltc/pk/ecc/ecc_get_curve.obj ltc/pk/ecc/ecc_get_key.obj ltc/pk/ecc/ecc_get_size.obj \ | |
113 | ltc/pk/ecc/ecc_import.obj ltc/pk/ecc/ecc_import_openssl.obj ltc/pk/ecc/ecc_import_pkcs8.obj \ | |
114 | ltc/pk/ecc/ecc_import_x509.obj ltc/pk/ecc/ecc_make_key.obj ltc/pk/ecc/ecc_set_dp.obj \ | |
115 | ltc/pk/ecc/ecc_set_dp_internal.obj ltc/pk/ecc/ecc_set_key.obj ltc/pk/ecc/ecc_shared_secret.obj \ | |
116 | ltc/pk/ecc/ecc_sign_hash.obj ltc/pk/ecc/ecc_sizes.obj ltc/pk/ecc/ecc_verify_hash.obj \ | |
117 | ltc/pk/ecc/ltc_ecc_export_point.obj ltc/pk/ecc/ltc_ecc_import_point.obj ltc/pk/ecc/ltc_ecc_is_point.obj \ | |
118 | ltc/pk/ecc/ltc_ecc_is_point_at_infinity.obj ltc/pk/ecc/ltc_ecc_map.obj ltc/pk/ecc/ltc_ecc_mul2add.obj \ | |
119 | ltc/pk/ecc/ltc_ecc_mulmod.obj ltc/pk/ecc/ltc_ecc_mulmod_timing.obj ltc/pk/ecc/ltc_ecc_points.obj \ | |
120 | ltc/pk/ecc/ltc_ecc_projective_add_point.obj ltc/pk/ecc/ltc_ecc_projective_dbl_point.obj \ | |
112 | ltc/pk/ecc/ecc_get_curve.obj ltc/pk/ecc/ecc_get_key.obj ltc/pk/ecc/ecc_get_oid_str.obj \ | |
113 | ltc/pk/ecc/ecc_get_size.obj ltc/pk/ecc/ecc_import.obj ltc/pk/ecc/ecc_import_openssl.obj \ | |
114 | ltc/pk/ecc/ecc_import_pkcs8.obj ltc/pk/ecc/ecc_import_x509.obj ltc/pk/ecc/ecc_make_key.obj \ | |
115 | ltc/pk/ecc/ecc_set_dp.obj ltc/pk/ecc/ecc_set_dp_internal.obj ltc/pk/ecc/ecc_set_key.obj \ | |
116 | ltc/pk/ecc/ecc_shared_secret.obj ltc/pk/ecc/ecc_sign_hash.obj ltc/pk/ecc/ecc_sizes.obj \ | |
117 | ltc/pk/ecc/ecc_verify_hash.obj ltc/pk/ecc/ltc_ecc_export_point.obj ltc/pk/ecc/ltc_ecc_import_point.obj \ | |
118 | ltc/pk/ecc/ltc_ecc_is_point.obj ltc/pk/ecc/ltc_ecc_is_point_at_infinity.obj ltc/pk/ecc/ltc_ecc_map.obj \ | |
119 | ltc/pk/ecc/ltc_ecc_mul2add.obj ltc/pk/ecc/ltc_ecc_mulmod.obj ltc/pk/ecc/ltc_ecc_mulmod_timing.obj \ | |
120 | ltc/pk/ecc/ltc_ecc_points.obj ltc/pk/ecc/ltc_ecc_projective_add_point.obj ltc/pk/ecc/ltc_ecc_projective_dbl_point.obj \ | |
121 | 121 | ltc/pk/ecc/ltc_ecc_verify_key.obj ltc/pk/pkcs1/pkcs_1_i2osp.obj ltc/pk/pkcs1/pkcs_1_mgf1.obj \ |
122 | 122 | ltc/pk/pkcs1/pkcs_1_oaep_decode.obj ltc/pk/pkcs1/pkcs_1_oaep_encode.obj ltc/pk/pkcs1/pkcs_1_os2ip.obj \ |
123 | 123 | ltc/pk/pkcs1/pkcs_1_pss_decode.obj ltc/pk/pkcs1/pkcs_1_pss_encode.obj ltc/pk/pkcs1/pkcs_1_v1_5_decode.obj \ |
131 | 131 | ltc/stream/chacha/chacha_ivctr32.obj ltc/stream/chacha/chacha_ivctr64.obj ltc/stream/chacha/chacha_keystream.obj \ |
132 | 132 | ltc/stream/chacha/chacha_setup.obj ltc/stream/rabbit/rabbit.obj ltc/stream/rc4/rc4_stream.obj \ |
133 | 133 | ltc/stream/salsa20/salsa20_crypt.obj ltc/stream/salsa20/salsa20_done.obj ltc/stream/salsa20/salsa20_ivctr64.obj \ |
134 | ltc/stream/salsa20/salsa20_keystream.obj ltc/stream/salsa20/salsa20_setup.obj ltc/stream/sober128/sober128_stream.obj \ | |
135 | ltc/stream/sosemanuk/sosemanuk.obj ltm/bncore.obj ltm/bn_error.obj ltm/bn_fast_mp_invmod.obj \ | |
136 | ltm/bn_fast_mp_montgomery_reduce.obj ltm/bn_fast_s_mp_mul_digs.obj ltm/bn_fast_s_mp_mul_high_digs.obj \ | |
137 | ltm/bn_fast_s_mp_sqr.obj ltm/bn_mp_2expt.obj ltm/bn_mp_abs.obj ltm/bn_mp_add.obj \ | |
138 | ltm/bn_mp_addmod.obj ltm/bn_mp_add_d.obj ltm/bn_mp_and.obj ltm/bn_mp_clamp.obj ltm/bn_mp_clear.obj \ | |
139 | ltm/bn_mp_clear_multi.obj ltm/bn_mp_cmp.obj ltm/bn_mp_cmp_d.obj ltm/bn_mp_cmp_mag.obj \ | |
140 | ltm/bn_mp_cnt_lsb.obj ltm/bn_mp_copy.obj ltm/bn_mp_count_bits.obj ltm/bn_mp_div.obj \ | |
141 | ltm/bn_mp_div_2.obj ltm/bn_mp_div_2d.obj ltm/bn_mp_div_3.obj ltm/bn_mp_div_d.obj \ | |
134 | ltc/stream/salsa20/salsa20_keystream.obj ltc/stream/salsa20/salsa20_setup.obj ltc/stream/salsa20/xsalsa20_setup.obj \ | |
135 | ltc/stream/sober128/sober128_stream.obj ltc/stream/sosemanuk/sosemanuk.obj ltm/bncore.obj \ | |
136 | ltm/bn_error.obj ltm/bn_fast_mp_invmod.obj ltm/bn_fast_mp_montgomery_reduce.obj ltm/bn_fast_s_mp_mul_digs.obj \ | |
137 | ltm/bn_fast_s_mp_mul_high_digs.obj ltm/bn_fast_s_mp_sqr.obj ltm/bn_mp_2expt.obj ltm/bn_mp_abs.obj \ | |
138 | ltm/bn_mp_add.obj ltm/bn_mp_addmod.obj ltm/bn_mp_add_d.obj ltm/bn_mp_and.obj ltm/bn_mp_clamp.obj \ | |
139 | ltm/bn_mp_clear.obj ltm/bn_mp_clear_multi.obj ltm/bn_mp_cmp.obj ltm/bn_mp_cmp_d.obj \ | |
140 | ltm/bn_mp_cmp_mag.obj ltm/bn_mp_cnt_lsb.obj ltm/bn_mp_copy.obj ltm/bn_mp_count_bits.obj \ | |
141 | ltm/bn_mp_div.obj ltm/bn_mp_div_2.obj ltm/bn_mp_div_2d.obj ltm/bn_mp_div_3.obj ltm/bn_mp_div_d.obj \ | |
142 | 142 | ltm/bn_mp_dr_is_modulus.obj ltm/bn_mp_dr_reduce.obj ltm/bn_mp_dr_setup.obj ltm/bn_mp_exch.obj \ |
143 | 143 | ltm/bn_mp_export.obj ltm/bn_mp_exptmod.obj ltm/bn_mp_exptmod_fast.obj ltm/bn_mp_expt_d.obj \ |
144 | 144 | ltm/bn_mp_expt_d_ex.obj ltm/bn_mp_exteuclid.obj ltm/bn_mp_fread.obj ltm/bn_mp_fwrite.obj \ |
145 | ltm/bn_mp_gcd.obj ltm/bn_mp_get_int.obj ltm/bn_mp_get_long.obj ltm/bn_mp_get_long_long.obj \ | |
146 | ltm/bn_mp_grow.obj ltm/bn_mp_import.obj ltm/bn_mp_init.obj ltm/bn_mp_init_copy.obj \ | |
147 | ltm/bn_mp_init_multi.obj ltm/bn_mp_init_set.obj ltm/bn_mp_init_set_int.obj ltm/bn_mp_init_size.obj \ | |
148 | ltm/bn_mp_invmod.obj ltm/bn_mp_invmod_slow.obj ltm/bn_mp_is_square.obj ltm/bn_mp_jacobi.obj \ | |
149 | ltm/bn_mp_karatsuba_mul.obj ltm/bn_mp_karatsuba_sqr.obj ltm/bn_mp_lcm.obj ltm/bn_mp_lshd.obj \ | |
150 | ltm/bn_mp_mod.obj ltm/bn_mp_mod_2d.obj ltm/bn_mp_mod_d.obj ltm/bn_mp_montgomery_calc_normalization.obj \ | |
145 | ltm/bn_mp_gcd.obj ltm/bn_mp_get_int.obj ltm/bn_mp_get_long.obj ltm/bn_mp_grow.obj \ | |
146 | ltm/bn_mp_import.obj ltm/bn_mp_init.obj ltm/bn_mp_init_copy.obj ltm/bn_mp_init_multi.obj \ | |
147 | ltm/bn_mp_init_set.obj ltm/bn_mp_init_set_int.obj ltm/bn_mp_init_size.obj ltm/bn_mp_invmod.obj \ | |
148 | ltm/bn_mp_invmod_slow.obj ltm/bn_mp_is_square.obj ltm/bn_mp_jacobi.obj ltm/bn_mp_karatsuba_mul.obj \ | |
149 | ltm/bn_mp_karatsuba_sqr.obj ltm/bn_mp_lcm.obj ltm/bn_mp_lshd.obj ltm/bn_mp_mod.obj \ | |
150 | ltm/bn_mp_mod_2d.obj ltm/bn_mp_mod_d.obj ltm/bn_mp_montgomery_calc_normalization.obj \ | |
151 | 151 | ltm/bn_mp_montgomery_reduce.obj ltm/bn_mp_montgomery_setup.obj ltm/bn_mp_mul.obj \ |
152 | 152 | ltm/bn_mp_mulmod.obj ltm/bn_mp_mul_2.obj ltm/bn_mp_mul_2d.obj ltm/bn_mp_mul_d.obj \ |
153 | 153 | ltm/bn_mp_neg.obj ltm/bn_mp_n_root.obj ltm/bn_mp_n_root_ex.obj ltm/bn_mp_or.obj ltm/bn_mp_prime_fermat.obj \ |
158 | 158 | ltm/bn_mp_reduce_2k.obj ltm/bn_mp_reduce_2k_l.obj ltm/bn_mp_reduce_2k_setup.obj ltm/bn_mp_reduce_2k_setup_l.obj \ |
159 | 159 | ltm/bn_mp_reduce_is_2k.obj ltm/bn_mp_reduce_is_2k_l.obj ltm/bn_mp_reduce_setup.obj \ |
160 | 160 | ltm/bn_mp_rshd.obj ltm/bn_mp_set.obj ltm/bn_mp_set_int.obj ltm/bn_mp_set_long.obj \ |
161 | ltm/bn_mp_set_long_long.obj ltm/bn_mp_shrink.obj ltm/bn_mp_signed_bin_size.obj ltm/bn_mp_sqr.obj \ | |
162 | ltm/bn_mp_sqrmod.obj ltm/bn_mp_sqrt.obj ltm/bn_mp_sqrtmod_prime.obj ltm/bn_mp_sub.obj \ | |
163 | ltm/bn_mp_submod.obj ltm/bn_mp_sub_d.obj ltm/bn_mp_toom_mul.obj ltm/bn_mp_toom_sqr.obj \ | |
164 | ltm/bn_mp_toradix.obj ltm/bn_mp_toradix_n.obj ltm/bn_mp_to_signed_bin.obj ltm/bn_mp_to_signed_bin_n.obj \ | |
161 | ltm/bn_mp_shrink.obj ltm/bn_mp_signed_bin_size.obj ltm/bn_mp_sqr.obj ltm/bn_mp_sqrmod.obj \ | |
162 | ltm/bn_mp_sqrt.obj ltm/bn_mp_sqrtmod_prime.obj ltm/bn_mp_sub.obj ltm/bn_mp_submod.obj \ | |
163 | ltm/bn_mp_sub_d.obj ltm/bn_mp_toom_mul.obj ltm/bn_mp_toom_sqr.obj ltm/bn_mp_toradix.obj \ | |
164 | ltm/bn_mp_toradix_n.obj ltm/bn_mp_to_signed_bin.obj ltm/bn_mp_to_signed_bin_n.obj \ | |
165 | 165 | ltm/bn_mp_to_unsigned_bin.obj ltm/bn_mp_to_unsigned_bin_n.obj ltm/bn_mp_unsigned_bin_size.obj \ |
166 | 166 | ltm/bn_mp_xor.obj ltm/bn_mp_zero.obj ltm/bn_prime_tab.obj ltm/bn_reverse.obj ltm/bn_s_mp_add.obj \ |
167 | 167 | ltm/bn_s_mp_exptmod.obj ltm/bn_s_mp_mul_digs.obj ltm/bn_s_mp_mul_high_digs.obj ltm/bn_s_mp_sqr.obj \ |
27 | 27 | Implementation of AES |
28 | 28 | */ |
29 | 29 | |
30 | #include "tomcrypt.h" | |
30 | #include "tomcrypt_private.h" | |
31 | 31 | |
32 | 32 | #ifdef LTC_RIJNDAEL |
33 | 33 |
12 | 12 | Authors: Paulo S.L.M. Barreto and Vincent Rijmen. |
13 | 13 | */ |
14 | 14 | |
15 | #include "tomcrypt.h" | |
15 | #include "tomcrypt_private.h" | |
16 | 16 | |
17 | 17 | #ifdef LTC_ANUBIS |
18 | 18 |
9 | 9 | @file blowfish.c |
10 | 10 | Implementation of the Blowfish block cipher, Tom St Denis |
11 | 11 | */ |
12 | #include "tomcrypt.h" | |
12 | #include "tomcrypt_private.h" | |
13 | 13 | |
14 | 14 | #ifdef LTC_BLOWFISH |
15 | 15 | |
393 | 393 | ulong32 L, R; |
394 | 394 | int r; |
395 | 395 | #ifndef __GNUC__ |
396 | ulong32 *S1, *S2, *S3, *S4; | |
396 | const ulong32 *S1, *S2, *S3, *S4; | |
397 | 397 | #endif |
398 | 398 | |
399 | 399 | LTC_ARGCHK(pt != NULL); |
455 | 455 | ulong32 L, R; |
456 | 456 | int r; |
457 | 457 | #ifndef __GNUC__ |
458 | ulong32 *S1, *S2, *S3, *S4; | |
458 | const ulong32 *S1, *S2, *S3, *S4; | |
459 | 459 | #endif |
460 | 460 | |
461 | 461 | LTC_ARGCHK(pt != NULL); |
11 | 11 | Implementation by Tom St Denis of Elliptic Semiconductor |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_CAMELLIA |
17 | 17 |
10 | 10 | @file cast5.c |
11 | 11 | Implementation of LTC_CAST5 (RFC 2144) by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_CAST5 |
16 | 16 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file des.c |
35 | 35 | { |
36 | 36 | "3des", |
37 | 37 | 14, |
38 | 24, 24, 8, 16, | |
38 | 16, 24, 8, 16, | |
39 | 39 | &des3_setup, |
40 | 40 | &des3_ecb_encrypt, |
41 | 41 | &des3_ecb_decrypt, |
2067 | 2067 | int des3_keysize(int *keysize) |
2068 | 2068 | { |
2069 | 2069 | LTC_ARGCHK(keysize != NULL); |
2070 | if(*keysize < 24) { | |
2071 | return CRYPT_INVALID_KEYSIZE; | |
2070 | if (*keysize < 16) | |
2071 | return CRYPT_INVALID_KEYSIZE; | |
2072 | if (*keysize < 24) { | |
2073 | *keysize = 16; | |
2074 | return CRYPT_OK; | |
2072 | 2075 | } |
2073 | 2076 | *keysize = 24; |
2074 | 2077 | return CRYPT_OK; |
21 | 21 | and Japan (JP 3225440) (expired May 16, 2011). |
22 | 22 | */ |
23 | 23 | |
24 | #include "tomcrypt.h" | |
24 | #include "tomcrypt_private.h" | |
25 | 25 | |
26 | 26 | #ifdef LTC_IDEA |
27 | 27 |
12 | 12 | Derived from the 3GPP standard source code |
13 | 13 | */ |
14 | 14 | |
15 | #include "tomcrypt.h" | |
15 | #include "tomcrypt_private.h" | |
16 | 16 | |
17 | 17 | #ifdef LTC_KASUMI |
18 | 18 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file khazad.c |
12 | 12 | Tom St Denis |
13 | 13 | */ |
14 | 14 | |
15 | #include "tomcrypt.h" | |
15 | #include "tomcrypt_private.h" | |
16 | 16 | |
17 | 17 | #ifdef LTC_KSEED |
18 | 18 |
10 | 10 | @file multi2.c |
11 | 11 | Multi-2 implementation (not public domain, hence the default disable) |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_MULTI2 |
16 | 16 |
9 | 9 | @file noekeon.c |
10 | 10 | Implementation of the Noekeon block cipher by Tom St Denis |
11 | 11 | */ |
12 | #include "tomcrypt.h" | |
12 | #include "tomcrypt_private.h" | |
13 | 13 | |
14 | 14 | #ifdef LTC_NOEKEON |
15 | 15 |
15 | 15 | * Thanks to CodeView, SoftIce, and D86 for helping bring this code to * |
16 | 16 | * the public. * |
17 | 17 | \**********************************************************************/ |
18 | #include "tomcrypt.h" | |
18 | #include "tomcrypt_private.h" | |
19 | 19 | |
20 | 20 | /** |
21 | 21 | @file rc2.c |
11 | 11 | LTC_RC5 code by Tom St Denis |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_RC5 |
17 | 17 |
10 | 10 | @file rc6.c |
11 | 11 | LTC_RC6 code by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_RC6 |
16 | 16 |
25 | 25 | * |
26 | 26 | *******************************************************************************/ |
27 | 27 | |
28 | #include "tomcrypt.h" | |
28 | #include "tomcrypt_private.h" | |
29 | 29 | |
30 | 30 | #ifdef LTC_SAFER |
31 | 31 |
10 | 10 | @file saferp.c |
11 | 11 | LTC_SAFER+ Implementation by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_SAFERP |
16 | 16 |
14 | 14 | https://en.wikipedia.org/wiki/Serpent_(cipher) |
15 | 15 | */ |
16 | 16 | |
17 | #include "tomcrypt.h" | |
17 | #include "tomcrypt_private.h" | |
18 | 18 | |
19 | 19 | #ifdef LTC_SERPENT |
20 | 20 |
10 | 10 | @file skipjack.c |
11 | 11 | Skipjack Implementation by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_SKIPJACK |
16 | 16 |
10 | 10 | @file twofish.c |
11 | 11 | Implementation of Twofish by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_TWOFISH |
16 | 16 | |
472 | 472 | const ulong32 *k; |
473 | 473 | int r; |
474 | 474 | #if !defined(LTC_TWOFISH_SMALL) && !defined(__GNUC__) |
475 | ulong32 *S1, *S2, *S3, *S4; | |
475 | const ulong32 *S1, *S2, *S3, *S4; | |
476 | 476 | #endif |
477 | 477 | |
478 | 478 | LTC_ARGCHK(pt != NULL); |
546 | 546 | const ulong32 *k; |
547 | 547 | int r; |
548 | 548 | #if !defined(LTC_TWOFISH_SMALL) && !defined(__GNUC__) |
549 | ulong32 *S1, *S2, *S3, *S4; | |
549 | const ulong32 *S1, *S2, *S3, *S4; | |
550 | 550 | #endif |
551 | 551 | |
552 | 552 | LTC_ARGCHK(pt != NULL); |
10 | 10 | @file xtea.c |
11 | 11 | Implementation of LTC_XTEA, Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_XTEA |
16 | 16 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_CCM_MODE |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_CCM_MODE |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_CCM_MODE |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_CCM_MODE |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ccm_memory.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_CCM_MODE |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_CCM_MODE |
11 | 11 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA20POLY1305_MODE |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA20POLY1305_MODE |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA20POLY1305_MODE |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA20POLY1305_MODE |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA20POLY1305_MODE |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA20POLY1305_MODE |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA20POLY1305_MODE |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA20POLY1305_MODE |
12 | 12 |
9 | 9 | @file eax_addheader.c |
10 | 10 | EAX implementation, add meta-data, by Tom St Denis |
11 | 11 | */ |
12 | #include "tomcrypt.h" | |
12 | #include "tomcrypt_private.h" | |
13 | 13 | |
14 | 14 | #ifdef LTC_EAX_MODE |
15 | 15 |
10 | 10 | @file eax_decrypt.c |
11 | 11 | EAX implementation, decrypt block, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_EAX_MODE |
16 | 16 |
10 | 10 | @file eax_decrypt_verify_memory.c |
11 | 11 | EAX implementation, decrypt block of memory, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_EAX_MODE |
16 | 16 |
10 | 10 | @file eax_done.c |
11 | 11 | EAX implementation, terminate session, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_EAX_MODE |
16 | 16 |
10 | 10 | @file eax_encrypt.c |
11 | 11 | EAX implementation, encrypt block by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_EAX_MODE |
16 | 16 |
10 | 10 | @file eax_encrypt_authenticate_memory.c |
11 | 11 | EAX implementation, encrypt a block of memory, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_EAX_MODE |
16 | 16 |
10 | 10 | @file eax_init.c |
11 | 11 | EAX implementation, initialized EAX state, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_EAX_MODE |
16 | 16 |
10 | 10 | @file gcm_add_aad.c |
11 | 11 | GCM implementation, Add AAD data to the stream, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_GCM_MODE |
16 | 16 |
10 | 10 | @file gcm_add_iv.c |
11 | 11 | GCM implementation, add IV data to the state, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_GCM_MODE |
16 | 16 |
10 | 10 | @file gcm_done.c |
11 | 11 | GCM implementation, Terminate the stream, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_GCM_MODE |
16 | 16 |
10 | 10 | @file gcm_gf_mult.c |
11 | 11 | GCM implementation, do the GF mult, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #if defined(LTC_GCM_TABLES) || defined(LTC_LRW_TABLES) || ((defined(LTC_GCM_MODE) || defined(LTC_GCM_MODE)) && defined(LTC_FAST)) |
16 | 16 |
10 | 10 | @file gcm_init.c |
11 | 11 | GCM implementation, initialize state, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_GCM_MODE |
16 | 16 |
10 | 10 | @file gcm_memory.c |
11 | 11 | GCM implementation, process a packet, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_GCM_MODE |
16 | 16 |
10 | 10 | @file gcm_mult_h.c |
11 | 11 | GCM implementation, do the GF mult, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #if defined(LTC_GCM_MODE) |
16 | 16 | /** |
10 | 10 | @file gcm_process.c |
11 | 11 | GCM implementation, process message data, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_GCM_MODE |
16 | 16 |
10 | 10 | @file gcm_reset.c |
11 | 11 | GCM implementation, reset a used state so it can accept IV data, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_GCM_MODE |
16 | 16 |
10 | 10 | @file ocb3_add_aad.c |
11 | 11 | OCB implementation, add AAD data, by Karel Miko |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_decrypt.c |
11 | 11 | OCB implementation, decrypt data, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_decrypt_last.c |
11 | 11 | OCB implementation, internal helper, by Karel Miko |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_decrypt_verify_memory.c |
11 | 11 | OCB implementation, helper to decrypt block of memory, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_done.c |
11 | 11 | OCB implementation, INTERNAL ONLY helper, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_encrypt.c |
11 | 11 | OCB implementation, encrypt data, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_encrypt_authenticate_memory.c |
11 | 11 | OCB implementation, encrypt block of memory, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_encrypt_last.c |
11 | 11 | OCB implementation, internal helper, by Karel Miko |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_init.c |
11 | 11 | OCB implementation, initialize state, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_int_ntz.c |
11 | 11 | OCB implementation, INTERNAL ONLY helper, by Tom St Denis |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
10 | 10 | @file ocb3_int_xor_blocks.c |
11 | 11 | OCB implementation, INTERNAL ONLY helper, by Karel Miko |
12 | 12 | */ |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_OCB3_MODE |
16 | 16 |
22 | 22 | */ |
23 | 23 | /* see also https://www.ietf.org/rfc/rfc7693.txt */ |
24 | 24 | |
25 | #include "tomcrypt.h" | |
25 | #include "tomcrypt_private.h" | |
26 | 26 | |
27 | 27 | #ifdef LTC_BLAKE2B |
28 | 28 | |
198 | 198 | return CRYPT_OK; |
199 | 199 | } |
200 | 200 | |
201 | /** | |
202 | Initialize the hash/MAC state | |
203 | ||
204 | Use this function to init for arbitrary sizes. | |
205 | ||
206 | Give a key and keylen to init for MAC mode. | |
207 | ||
208 | @param md The hash state you wish to initialize | |
209 | @param outlen The desired output-length | |
210 | @param key The key of the MAC | |
211 | @param keylen The length of the key | |
212 | @return CRYPT_OK if successful | |
213 | */ | |
201 | 214 | int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key, unsigned long keylen) |
202 | 215 | { |
203 | 216 | unsigned char P[BLAKE2B_PARAM_SIZE]; |
236 | 249 | return CRYPT_OK; |
237 | 250 | } |
238 | 251 | |
252 | /** | |
253 | Initialize the hash state | |
254 | @param md The hash state you wish to initialize | |
255 | @return CRYPT_OK if successful | |
256 | */ | |
239 | 257 | int blake2b_160_init(hash_state *md) { return blake2b_init(md, 20, NULL, 0); } |
240 | 258 | |
259 | /** | |
260 | Initialize the hash state | |
261 | @param md The hash state you wish to initialize | |
262 | @return CRYPT_OK if successful | |
263 | */ | |
241 | 264 | int blake2b_256_init(hash_state *md) { return blake2b_init(md, 32, NULL, 0); } |
242 | 265 | |
266 | /** | |
267 | Initialize the hash state | |
268 | @param md The hash state you wish to initialize | |
269 | @return CRYPT_OK if successful | |
270 | */ | |
243 | 271 | int blake2b_384_init(hash_state *md) { return blake2b_init(md, 48, NULL, 0); } |
244 | 272 | |
273 | /** | |
274 | Initialize the hash state | |
275 | @param md The hash state you wish to initialize | |
276 | @return CRYPT_OK if successful | |
277 | */ | |
245 | 278 | int blake2b_512_init(hash_state *md) { return blake2b_init(md, 64, NULL, 0); } |
246 | 279 | |
247 | 280 | #define G(r, i, a, b, c, d) \ |
327 | 360 | } |
328 | 361 | #endif |
329 | 362 | |
363 | /** | |
364 | Process a block of memory through the hash | |
365 | @param md The hash state | |
366 | @param in The data to hash | |
367 | @param inlen The length of the data (octets) | |
368 | @return CRYPT_OK if successful | |
369 | */ | |
330 | 370 | int blake2b_process(hash_state *md, const unsigned char *in, unsigned long inlen) |
331 | 371 | { |
332 | 372 | LTC_ARGCHK(md != NULL); |
359 | 399 | return CRYPT_OK; |
360 | 400 | } |
361 | 401 | |
402 | /** | |
403 | Terminate the hash to get the digest | |
404 | @param md The hash state | |
405 | @param out [out] The destination of the hash (size depending on the length used on init) | |
406 | @return CRYPT_OK if successful | |
407 | */ | |
362 | 408 | int blake2b_done(hash_state *md, unsigned char *out) |
363 | 409 | { |
364 | 410 | unsigned char buffer[BLAKE2B_OUTBYTES] = { 0 }; |
22 | 22 | */ |
23 | 23 | /* see also https://www.ietf.org/rfc/rfc7693.txt */ |
24 | 24 | |
25 | #include "tomcrypt.h" | |
25 | #include "tomcrypt_private.h" | |
26 | 26 | |
27 | 27 | #ifdef LTC_BLAKE2S |
28 | 28 | |
192 | 192 | return CRYPT_OK; |
193 | 193 | } |
194 | 194 | |
195 | /** | |
196 | Initialize the hash/MAC state | |
197 | ||
198 | Use this function to init for arbitrary sizes. | |
199 | ||
200 | Give a key and keylen to init for MAC mode. | |
201 | ||
202 | @param md The hash state you wish to initialize | |
203 | @param outlen The desired output-length | |
204 | @param key The key of the MAC | |
205 | @param keylen The length of the key | |
206 | @return CRYPT_OK if successful | |
207 | */ | |
195 | 208 | int blake2s_init(hash_state *md, unsigned long outlen, const unsigned char *key, unsigned long keylen) |
196 | 209 | { |
197 | 210 | unsigned char P[BLAKE2S_PARAM_SIZE]; |
229 | 242 | return CRYPT_OK; |
230 | 243 | } |
231 | 244 | |
245 | /** | |
246 | Initialize the hash state | |
247 | @param md The hash state you wish to initialize | |
248 | @return CRYPT_OK if successful | |
249 | */ | |
232 | 250 | int blake2s_128_init(hash_state *md) { return blake2s_init(md, 16, NULL, 0); } |
233 | 251 | |
252 | /** | |
253 | Initialize the hash state | |
254 | @param md The hash state you wish to initialize | |
255 | @return CRYPT_OK if successful | |
256 | */ | |
234 | 257 | int blake2s_160_init(hash_state *md) { return blake2s_init(md, 20, NULL, 0); } |
235 | 258 | |
259 | /** | |
260 | Initialize the hash state | |
261 | @param md The hash state you wish to initialize | |
262 | @return CRYPT_OK if successful | |
263 | */ | |
236 | 264 | int blake2s_224_init(hash_state *md) { return blake2s_init(md, 28, NULL, 0); } |
237 | 265 | |
266 | /** | |
267 | Initialize the hash state | |
268 | @param md The hash state you wish to initialize | |
269 | @return CRYPT_OK if successful | |
270 | */ | |
238 | 271 | int blake2s_256_init(hash_state *md) { return blake2s_init(md, 32, NULL, 0); } |
239 | 272 | |
240 | 273 | #define G(r, i, a, b, c, d) \ |
315 | 348 | } |
316 | 349 | #endif |
317 | 350 | |
351 | /** | |
352 | Process a block of memory through the hash | |
353 | @param md The hash state | |
354 | @param in The data to hash | |
355 | @param inlen The length of the data (octets) | |
356 | @return CRYPT_OK if successful | |
357 | */ | |
318 | 358 | int blake2s_process(hash_state *md, const unsigned char *in, unsigned long inlen) |
319 | 359 | { |
320 | 360 | LTC_ARGCHK(md != NULL); |
347 | 387 | return CRYPT_OK; |
348 | 388 | } |
349 | 389 | |
390 | /** | |
391 | Terminate the hash to get the digest | |
392 | @param md The hash state | |
393 | @param out [out] The destination of the hash (size depending on the length used on init) | |
394 | @return CRYPT_OK if successful | |
395 | */ | |
350 | 396 | int blake2s_done(hash_state *md, unsigned char *out) |
351 | 397 | { |
352 | 398 | unsigned char buffer[BLAKE2S_OUTBYTES] = { 0 }; |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file chc.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifndef LTC_NO_FILE |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifndef LTC_NO_FILE |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_HASH_HELPERS |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 | #ifdef LTC_HASH_HELPERS |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @param md2.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @param md4.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @param rmd128.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rmd160.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @param rmd256.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rmd320.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file sha1.c |
10 | 10 | LTC_SHA-224 new NIST standard based off of LTC_SHA-256 truncated to 224 bits (Tom St Denis) |
11 | 11 | */ |
12 | 12 | |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #if defined(LTC_SHA224) && defined(LTC_SHA256) |
16 | 16 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file sha256.c |
10 | 10 | LTC_SHA384 hash included in sha512.c, Tom St Denis |
11 | 11 | */ |
12 | 12 | |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #if defined(LTC_SHA384) && defined(LTC_SHA512) |
16 | 16 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @param sha512.c |
10 | 10 | SHA512/224 hash included in sha512.c |
11 | 11 | */ |
12 | 12 | |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #if defined(LTC_SHA512_224) && defined(LTC_SHA512) |
16 | 16 |
10 | 10 | SHA512/256 hash included in sha512.c |
11 | 11 | */ |
12 | 12 | |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #if defined(LTC_SHA512_256) && defined(LTC_SHA512) |
16 | 16 |
8 | 8 | |
9 | 9 | /* based on https://github.com/brainhub/SHA3IUF (public domain) */ |
10 | 10 | |
11 | #include "tomcrypt.h" | |
11 | #include "tomcrypt_private.h" | |
12 | 12 | |
13 | 13 | #ifdef LTC_SHA3 |
14 | 14 |
8 | 8 | |
9 | 9 | /* based on https://github.com/brainhub/SHA3IUF (public domain) */ |
10 | 10 | |
11 | #include "tomcrypt.h" | |
11 | #include "tomcrypt_private.h" | |
12 | 12 | |
13 | 13 | #ifdef LTC_SHA3 |
14 | 14 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file tiger.c |
11 | 11 | LTC_WHIRLPOOL (using their new sbox) hash function by Tom St Denis |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_WHIRLPOOL |
17 | 17 |
1030 | 1030 | |
1031 | 1031 | #endif /* LTC_SALSA20 */ |
1032 | 1032 | |
1033 | #ifdef LTC_XSALSA20 | |
1034 | ||
1035 | int xsalsa20_setup(salsa20_state *st, const unsigned char *key, unsigned long keylen, | |
1036 | const unsigned char *nonce, unsigned long noncelen, | |
1037 | int rounds); | |
1038 | int xsalsa20_test(void); | |
1039 | ||
1040 | #endif /* LTC_XSALSA20 */ | |
1041 | ||
1033 | 1042 | #ifdef LTC_SOSEMANUK |
1034 | 1043 | |
1035 | 1044 | typedef struct { |
207 | 207 | /* stream ciphers */ |
208 | 208 | #define LTC_CHACHA |
209 | 209 | #define LTC_SALSA20 |
210 | #define LTC_XSALSA20 | |
210 | 211 | #define LTC_SOSEMANUK |
211 | 212 | #define LTC_RABBIT |
212 | 213 | #define LTC_RC4_STREAM |
363 | 364 | /* time-based rate limit of the reseeding */ |
364 | 365 | #define LTC_FORTUNA_RESEED_RATELIMIT_TIMED |
365 | 366 | |
367 | /* with non-glibc or glibc 2.17+ prefer clock_gettime over gettimeofday */ | |
368 | #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) | |
369 | #if __GLIBC_PREREQ(2, 17) | |
370 | #define LTC_CLOCK_GETTIME | |
371 | #endif | |
372 | #elif defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L | |
373 | #define LTC_CLOCK_GETTIME | |
374 | #endif | |
375 | ||
366 | 376 | #else |
367 | 377 | |
368 | 378 | #ifndef LTC_FORTUNA_WD |
413 | 423 | #define LTC_DH6144 |
414 | 424 | #define LTC_DH8192 |
415 | 425 | #endif |
416 | ||
417 | /* Include Katja (a Rabin variant like RSA) */ | |
418 | /* #define LTC_MKAT */ | |
419 | 426 | |
420 | 427 | /* Digital Signature Algorithm */ |
421 | 428 | #define LTC_MDSA |
537 | 544 | #endif |
538 | 545 | #endif |
539 | 546 | |
540 | #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_MKAT) | |
547 | #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) | |
541 | 548 | /* Include the MPI functionality? (required by the PK algorithms) */ |
542 | 549 | #define LTC_MPI |
543 | 550 | |
567 | 574 | #error ASN.1 DER requires MPI functionality |
568 | 575 | #endif |
569 | 576 | |
570 | #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC) || defined(LTC_MKAT)) && !defined(LTC_DER) | |
577 | #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC)) && !defined(LTC_DER) | |
571 | 578 | #error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled |
572 | 579 | #endif |
573 | 580 | |
577 | 584 | |
578 | 585 | #if defined(LTC_CHACHA20_PRNG) && !defined(LTC_CHACHA) |
579 | 586 | #error LTC_CHACHA20_PRNG requires LTC_CHACHA |
587 | #endif | |
588 | ||
589 | #if defined(LTC_XSALSA20) && !defined(LTC_SALSA20) | |
590 | #error LTC_XSALSA20 requires LTC_SALSA20 | |
580 | 591 | #endif |
581 | 592 | |
582 | 593 | #if defined(LTC_RC4) && !defined(LTC_RC4_STREAM) |
506 | 506 | int hash_file(int hash, const char *fname, unsigned char *out, unsigned long *outlen); |
507 | 507 | #endif |
508 | 508 | |
509 | /* a simple macro for making hash "process" functions */ | |
510 | #define HASH_PROCESS(func_name, compress_name, state_var, block_size) \ | |
511 | int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \ | |
512 | { \ | |
513 | unsigned long n; \ | |
514 | int err; \ | |
515 | LTC_ARGCHK(md != NULL); \ | |
516 | LTC_ARGCHK(in != NULL); \ | |
517 | if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \ | |
518 | return CRYPT_INVALID_ARG; \ | |
519 | } \ | |
520 | if ((md-> state_var .length + inlen) < md-> state_var .length) { \ | |
521 | return CRYPT_HASH_OVERFLOW; \ | |
522 | } \ | |
523 | while (inlen > 0) { \ | |
524 | if (md-> state_var .curlen == 0 && inlen >= block_size) { \ | |
525 | if ((err = compress_name (md, in)) != CRYPT_OK) { \ | |
526 | return err; \ | |
527 | } \ | |
528 | md-> state_var .length += block_size * 8; \ | |
529 | in += block_size; \ | |
530 | inlen -= block_size; \ | |
531 | } else { \ | |
532 | n = MIN(inlen, (block_size - md-> state_var .curlen)); \ | |
533 | XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \ | |
534 | md-> state_var .curlen += n; \ | |
535 | in += n; \ | |
536 | inlen -= n; \ | |
537 | if (md-> state_var .curlen == block_size) { \ | |
538 | if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) { \ | |
539 | return err; \ | |
540 | } \ | |
541 | md-> state_var .length += 8*block_size; \ | |
542 | md-> state_var .curlen = 0; \ | |
543 | } \ | |
544 | } \ | |
545 | } \ | |
546 | return CRYPT_OK; \ | |
547 | } | |
548 | ||
549 | 509 | /* ref: $Format:%D$ */ |
550 | 510 | /* git commit: $Format:%H$ */ |
551 | 511 | /* commit time: $Format:%ai$ */ |
145 | 145 | int blake2bmac_test(void); |
146 | 146 | #endif /* LTC_BLAKE2BMAC */ |
147 | 147 | |
148 | ||
148 | 149 | #ifdef LTC_PELICAN |
149 | 150 | |
150 | 151 | typedef struct pelican_state |
390 | 391 | |
391 | 392 | int ocb3_test(void); |
392 | 393 | |
393 | #ifdef LTC_SOURCE | |
394 | /* internal helper functions */ | |
395 | int ocb3_int_ntz(unsigned long x); | |
396 | void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const unsigned char *block_b, unsigned long block_len); | |
397 | #endif /* LTC_SOURCE */ | |
398 | ||
399 | 394 | #endif /* LTC_OCB3_MODE */ |
400 | 395 | |
401 | 396 | #ifdef LTC_CCM_MODE |
523 | 523 | extern const ltc_math_descriptor gmp_desc; |
524 | 524 | #endif |
525 | 525 | |
526 | #if !defined(DESC_DEF_ONLY) && defined(LTC_SOURCE) | |
527 | ||
528 | #define MP_DIGIT_BIT ltc_mp.bits_per_digit | |
529 | ||
530 | /* some handy macros */ | |
531 | #define mp_init(a) ltc_mp.init(a) | |
532 | #define mp_init_multi ltc_init_multi | |
533 | #define mp_clear(a) ltc_mp.deinit(a) | |
534 | #define mp_clear_multi ltc_deinit_multi | |
535 | #define mp_cleanup_multi ltc_cleanup_multi | |
536 | #define mp_init_copy(a, b) ltc_mp.init_copy(a, b) | |
537 | ||
538 | #define mp_neg(a, b) ltc_mp.neg(a, b) | |
539 | #define mp_copy(a, b) ltc_mp.copy(a, b) | |
540 | ||
541 | #define mp_set(a, b) ltc_mp.set_int(a, b) | |
542 | #define mp_set_int(a, b) ltc_mp.set_int(a, b) | |
543 | #define mp_get_int(a) ltc_mp.get_int(a) | |
544 | #define mp_get_digit(a, n) ltc_mp.get_digit(a, n) | |
545 | #define mp_get_digit_count(a) ltc_mp.get_digit_count(a) | |
546 | #define mp_cmp(a, b) ltc_mp.compare(a, b) | |
547 | #define mp_cmp_d(a, b) ltc_mp.compare_d(a, b) | |
548 | #define mp_count_bits(a) ltc_mp.count_bits(a) | |
549 | #define mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a) | |
550 | #define mp_2expt(a, b) ltc_mp.twoexpt(a, b) | |
551 | ||
552 | #define mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c) | |
553 | #define mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c) | |
554 | #define mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a) | |
555 | #define mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b) | |
556 | #define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c) | |
557 | ||
558 | #define mp_add(a, b, c) ltc_mp.add(a, b, c) | |
559 | #define mp_add_d(a, b, c) ltc_mp.addi(a, b, c) | |
560 | #define mp_sub(a, b, c) ltc_mp.sub(a, b, c) | |
561 | #define mp_sub_d(a, b, c) ltc_mp.subi(a, b, c) | |
562 | #define mp_mul(a, b, c) ltc_mp.mul(a, b, c) | |
563 | #define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c) | |
564 | #define mp_sqr(a, b) ltc_mp.sqr(a, b) | |
565 | #define mp_sqrtmod_prime(a, b, c) ltc_mp.sqrtmod_prime(a, b, c) | |
566 | #define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d) | |
567 | #define mp_div_2(a, b) ltc_mp.div_2(a, b) | |
568 | #define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c) | |
569 | #define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c) | |
570 | #define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c) | |
571 | #define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c) | |
572 | ||
573 | #define mp_addmod(a, b, c, d) ltc_mp.addmod(a, b, c, d) | |
574 | #define mp_submod(a, b, c, d) ltc_mp.submod(a, b, c, d) | |
575 | #define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d) | |
576 | #define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c) | |
577 | #define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c) | |
578 | ||
579 | #define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b) | |
580 | #define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b) | |
581 | #define mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c) | |
582 | #define mp_montgomery_free(a) ltc_mp.montgomery_deinit(a) | |
583 | ||
584 | #define mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d) | |
585 | #define mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, b, c) | |
586 | ||
587 | #define mp_iszero(a) (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO) | |
588 | #define mp_isodd(a) (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO) | |
589 | #define mp_exch(a, b) do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0) | |
590 | ||
591 | #define mp_tohex(a, b) mp_toradix(a, b, 16) | |
592 | ||
593 | #define mp_rand(a, b) ltc_mp.rand(a, b) | |
594 | ||
595 | #endif | |
596 | ||
597 | 526 | /* ref: $Format:%D$ */ |
598 | 527 | /* git commit: $Format:%H$ */ |
599 | 528 | /* commit time: $Format:%ai$ */ |
53 | 53 | #ifdef LTC_BASE16 |
54 | 54 | int base16_encode(const unsigned char *in, unsigned long inlen, |
55 | 55 | char *out, unsigned long *outlen, |
56 | int caps); | |
56 | unsigned int options); | |
57 | 57 | int base16_decode(const char *in, unsigned long inlen, |
58 | 58 | unsigned char *out, unsigned long *outlen); |
59 | 59 | #endif |
84 | 84 | /* ---- MEM routines ---- */ |
85 | 85 | int mem_neq(const void *a, const void *b, size_t len); |
86 | 86 | void zeromem(volatile void *dst, size_t len); |
87 | #ifdef LTC_SOURCE | |
88 | void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned long len, int coz); | |
89 | #endif | |
90 | 87 | void burn_stack(unsigned long len); |
91 | 88 | |
92 | 89 | const char *error_to_string(int err); |
154 | 151 | |
155 | 152 | int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded_length, unsigned long mode); |
156 | 153 | int padding_depad(const unsigned char *data, unsigned long *length, unsigned long mode); |
157 | ||
158 | #ifdef LTC_SOURCE | |
159 | /* internal helper functions */ | |
160 | #define LTC_PAD_MASK (0xF000U) | |
161 | #endif | |
162 | 154 | #endif /* LTC_PADDING */ |
163 | 155 | |
164 | 156 | int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which); |
23 | 23 | }; |
24 | 24 | |
25 | 25 | int rand_prime(void *N, long len, prng_state *prng, int wprng); |
26 | ||
27 | #ifdef LTC_SOURCE | |
28 | /* internal helper functions */ | |
29 | int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng); | |
30 | int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng); | |
31 | ||
32 | enum public_key_algorithms { | |
33 | PKA_RSA, | |
34 | PKA_DSA, | |
35 | PKA_EC, | |
36 | PKA_EC_PRIMEF | |
37 | }; | |
38 | ||
39 | typedef struct Oid { | |
40 | unsigned long OID[16]; | |
41 | /** Number of OID digits in use */ | |
42 | unsigned long OIDlen; | |
43 | } oid_st; | |
44 | ||
45 | int pk_get_oid(int pk, oid_st *st); | |
46 | int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen); | |
47 | int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen); | |
48 | #endif /* LTC_SOURCE */ | |
49 | 26 | |
50 | 27 | /* ---- RSA ---- */ |
51 | 28 | #ifdef LTC_MRSA |
148 | 125 | rsa_key *key); |
149 | 126 | #endif |
150 | 127 | |
151 | /* ---- Katja ---- */ | |
152 | #ifdef LTC_MKAT | |
153 | ||
154 | /* Min and Max KAT key sizes (in bits) */ | |
155 | #define MIN_KAT_SIZE 1024 | |
156 | #define MAX_KAT_SIZE 4096 | |
157 | ||
158 | /** Katja PKCS style key */ | |
159 | typedef struct KAT_key { | |
160 | /** Type of key, PK_PRIVATE or PK_PUBLIC */ | |
161 | int type; | |
162 | /** The private exponent */ | |
163 | void *d; | |
164 | /** The modulus */ | |
165 | void *N; | |
166 | /** The p factor of N */ | |
167 | void *p; | |
168 | /** The q factor of N */ | |
169 | void *q; | |
170 | /** The 1/q mod p CRT param */ | |
171 | void *qP; | |
172 | /** The d mod (p - 1) CRT param */ | |
173 | void *dP; | |
174 | /** The d mod (q - 1) CRT param */ | |
175 | void *dQ; | |
176 | /** The pq param */ | |
177 | void *pq; | |
178 | } katja_key; | |
179 | ||
180 | int katja_make_key(prng_state *prng, int wprng, int size, katja_key *key); | |
181 | ||
182 | int katja_exptmod(const unsigned char *in, unsigned long inlen, | |
183 | unsigned char *out, unsigned long *outlen, int which, | |
184 | katja_key *key); | |
185 | ||
186 | void katja_free(katja_key *key); | |
187 | ||
188 | /* These use PKCS #1 v2.0 padding */ | |
189 | int katja_encrypt_key(const unsigned char *in, unsigned long inlen, | |
190 | unsigned char *out, unsigned long *outlen, | |
191 | const unsigned char *lparam, unsigned long lparamlen, | |
192 | prng_state *prng, int prng_idx, int hash_idx, katja_key *key); | |
193 | ||
194 | int katja_decrypt_key(const unsigned char *in, unsigned long inlen, | |
195 | unsigned char *out, unsigned long *outlen, | |
196 | const unsigned char *lparam, unsigned long lparamlen, | |
197 | int hash_idx, int *stat, | |
198 | katja_key *key); | |
199 | ||
200 | /* PKCS #1 import/export */ | |
201 | int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key); | |
202 | int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key); | |
203 | ||
204 | #endif | |
205 | ||
206 | 128 | /* ---- DH Routines ---- */ |
207 | 129 | #ifdef LTC_MDH |
208 | 130 | |
234 | 156 | void dh_free(dh_key *key); |
235 | 157 | |
236 | 158 | int dh_export_key(void *out, unsigned long *outlen, int type, const dh_key *key); |
237 | ||
238 | #ifdef LTC_SOURCE | |
239 | typedef struct { | |
240 | int size; | |
241 | const char *name, *base, *prime; | |
242 | } ltc_dh_set_type; | |
243 | ||
244 | extern const ltc_dh_set_type ltc_dh_sets[]; | |
245 | ||
246 | /* internal helper functions */ | |
247 | int dh_check_pubkey(const dh_key *key); | |
248 | #endif | |
249 | ||
250 | 159 | #endif /* LTC_MDH */ |
251 | 160 | |
252 | 161 | |
346 | 255 | int ecc_generate_key(prng_state *prng, int wprng, ecc_key *key); |
347 | 256 | int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key *key); |
348 | 257 | int ecc_get_key(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key); |
258 | int ecc_get_oid_str(char *out, unsigned long *outlen, const ecc_key *key); | |
349 | 259 | |
350 | 260 | int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key); |
351 | 261 | int ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_curve *cu); |
391 | 301 | int ecc_verify_hash(const unsigned char *sig, unsigned long siglen, |
392 | 302 | const unsigned char *hash, unsigned long hashlen, |
393 | 303 | int *stat, const ecc_key *key); |
394 | ||
395 | ||
396 | #ifdef LTC_SOURCE | |
397 | /* INTERNAL ONLY - it should be later moved to src/headers/tomcrypt_internal.h */ | |
398 | ||
399 | int ecc_set_dp_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key); | |
400 | int ecc_copy_dp(const ecc_key *srckey, ecc_key *key); | |
401 | int ecc_set_dp_by_size(int size, ecc_key *key); | |
402 | ||
403 | /* low level functions */ | |
404 | ecc_point *ltc_ecc_new_point(void); | |
405 | void ltc_ecc_del_point(ecc_point *p); | |
406 | int ltc_ecc_set_point_xyz(ltc_mp_digit x, ltc_mp_digit y, ltc_mp_digit z, ecc_point *p); | |
407 | int ltc_ecc_copy_point(const ecc_point *src, ecc_point *dst); | |
408 | int ltc_ecc_is_point(const ltc_ecc_dp *dp, void *x, void *y); | |
409 | int ltc_ecc_is_point_at_infinity(const ecc_point *P, void *modulus, int *retval); | |
410 | int ltc_ecc_import_point(const unsigned char *in, unsigned long inlen, void *prime, void *a, void *b, void *x, void *y); | |
411 | int ltc_ecc_export_point(unsigned char *out, unsigned long *outlen, void *x, void *y, unsigned long size, int compressed); | |
412 | int ltc_ecc_verify_key(const ecc_key *key); | |
413 | ||
414 | /* point ops (mp == montgomery digit) */ | |
415 | #if !defined(LTC_MECC_ACCEL) || defined(LTM_DESC) || defined(GMP_DESC) | |
416 | /* R = 2P */ | |
417 | int ltc_ecc_projective_dbl_point(const ecc_point *P, ecc_point *R, void *ma, void *modulus, void *mp); | |
418 | ||
419 | /* R = P + Q */ | |
420 | int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_point *R, void *ma, void *modulus, void *mp); | |
421 | #endif | |
422 | ||
423 | #if defined(LTC_MECC_FP) | |
424 | /* optimized point multiplication using fixed point cache (HAC algorithm 14.117) */ | |
425 | int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *a, void *modulus, int map); | |
426 | ||
427 | /* functions for saving/loading/freeing/adding to fixed point cache */ | |
428 | int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen); | |
429 | int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen); | |
430 | void ltc_ecc_fp_free(void); | |
431 | int ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock); | |
432 | ||
433 | /* lock/unlock all points currently in fixed point cache */ | |
434 | void ltc_ecc_fp_tablelock(int lock); | |
435 | #endif | |
436 | ||
437 | /* R = kG */ | |
438 | int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *modulus, int map); | |
439 | ||
440 | #ifdef LTC_ECC_SHAMIR | |
441 | /* kA*A + kB*B = C */ | |
442 | int ltc_ecc_mul2add(const ecc_point *A, void *kA, | |
443 | const ecc_point *B, void *kB, | |
444 | ecc_point *C, | |
445 | void *ma, | |
446 | void *modulus); | |
447 | ||
448 | #ifdef LTC_MECC_FP | |
449 | /* Shamir's trick with optimized point multiplication using fixed point cache */ | |
450 | int ltc_ecc_fp_mul2add(const ecc_point *A, void *kA, | |
451 | const ecc_point *B, void *kB, | |
452 | ecc_point *C, | |
453 | void *ma, | |
454 | void *modulus); | |
455 | #endif | |
456 | ||
457 | #endif | |
458 | ||
459 | ||
460 | /* map P to affine from projective */ | |
461 | int ltc_ecc_map(ecc_point *P, void *modulus, void *mp); | |
462 | ||
463 | #endif /* LTC_SOURCE */ | |
464 | 304 | |
465 | 305 | #endif |
466 | 306 | |
538 | 378 | int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key); |
539 | 379 | int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_key *key); |
540 | 380 | int dsa_verify_key(const dsa_key *key, int *stat); |
541 | #ifdef LTC_SOURCE | |
542 | /* internal helper functions */ | |
543 | int dsa_int_validate_xy(const dsa_key *key, int *stat); | |
544 | int dsa_int_validate_pqg(const dsa_key *key, int *stat); | |
545 | int dsa_int_validate_primes(const dsa_key *key, int *stat); | |
546 | #endif | |
547 | 381 | int dsa_shared_secret(void *private_key, void *base, |
548 | 382 | const dsa_key *public_key, |
549 | 383 | unsigned char *out, unsigned long *outlen); |
550 | #endif | |
384 | #endif /* LTC_MDSA */ | |
551 | 385 | |
552 | 386 | #ifdef LTC_DER |
553 | 387 | /* DER handling */ |
710 | 544 | unsigned long *outlen, |
711 | 545 | unsigned long *payloadlen); |
712 | 546 | |
713 | #ifdef LTC_SOURCE | |
714 | /* internal helper functions */ | |
715 | int der_decode_custom_type_ex(const unsigned char *in, unsigned long inlen, | |
716 | ltc_asn1_list *root, | |
717 | ltc_asn1_list *list, unsigned long outlen, unsigned int flags); | |
718 | ||
719 | int der_encode_asn1_identifier(const ltc_asn1_list *id, unsigned char *out, unsigned long *outlen); | |
720 | int der_decode_asn1_identifier(const unsigned char *in, unsigned long *inlen, ltc_asn1_list *id); | |
721 | int der_length_asn1_identifier(const ltc_asn1_list *id, unsigned long *idlen); | |
722 | ||
723 | int der_encode_asn1_length(unsigned long len, unsigned char* out, unsigned long* outlen); | |
724 | int der_decode_asn1_length(const unsigned char* len, unsigned long* lenlen, unsigned long* outlen); | |
725 | int der_length_asn1_length(unsigned long len, unsigned long *outlen); | |
726 | ||
727 | int der_length_sequence_ex(const ltc_asn1_list *list, unsigned long inlen, | |
728 | unsigned long *outlen, unsigned long *payloadlen); | |
729 | ||
730 | extern const ltc_asn1_type der_asn1_tag_to_type_map[]; | |
731 | extern const unsigned long der_asn1_tag_to_type_map_sz; | |
732 | ||
733 | extern const int der_asn1_type_to_identifier_map[]; | |
734 | extern const unsigned long der_asn1_type_to_identifier_map_sz; | |
735 | #endif /* LTC_SOURCE */ | |
736 | ||
737 | 547 | /* SET */ |
738 | 548 | #define der_decode_set(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, LTC_DER_SEQ_SET) |
739 | 549 | #define der_length_set der_length_sequence |
746 | 556 | /* VA list handy helpers with triplets of <type, size, data> */ |
747 | 557 | int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...); |
748 | 558 | int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...); |
749 | #ifdef LTC_SOURCE | |
750 | /* internal helper functions */ | |
751 | int der_decode_sequence_multi_ex(const unsigned char *in, unsigned long inlen, unsigned int flags, ...); | |
752 | #endif /* LTC_SOURCE */ | |
753 | 559 | |
754 | 560 | /* FLEXI DECODER handle unknown list decoder */ |
755 | 561 | int der_decode_sequence_flexi(const unsigned char *in, unsigned long *inlen, ltc_asn1_list **out); |
814 | 620 | unsigned char *out, unsigned long *outlen); |
815 | 621 | int der_length_teletex_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen); |
816 | 622 | |
817 | #ifdef LTC_SOURCE | |
818 | /* internal helper functions */ | |
819 | int der_teletex_char_encode(int c); | |
820 | int der_teletex_value_decode(int v); | |
821 | #endif /* LTC_SOURCE */ | |
822 | ||
823 | ||
824 | 623 | /* PRINTABLE STRING */ |
825 | 624 | int der_encode_printable_string(const unsigned char *in, unsigned long inlen, |
826 | 625 | unsigned char *out, unsigned long *outlen); |
833 | 632 | |
834 | 633 | /* UTF-8 */ |
835 | 634 | #if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(__WCHAR_MAX__) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED) || defined (__WCHAR_TYPE__)) && !defined(LTC_NO_WCHAR) |
836 | #include <wchar.h> | |
837 | #if defined(__WCHAR_MAX__) | |
838 | #define LTC_WCHAR_MAX __WCHAR_MAX__ | |
839 | #elif defined(WCHAR_MAX) | |
840 | #define LTC_WCHAR_MAX WCHAR_MAX | |
841 | #endif | |
635 | #if defined(__WCHAR_MAX__) | |
636 | #define LTC_WCHAR_MAX __WCHAR_MAX__ | |
637 | #else | |
638 | #include <wchar.h> | |
639 | #define LTC_WCHAR_MAX WCHAR_MAX | |
640 | #endif | |
842 | 641 | /* please note that it might happen that LTC_WCHAR_MAX is undefined */ |
843 | 642 | #else |
844 | typedef ulong32 wchar_t; | |
845 | #define LTC_WCHAR_MAX 0xFFFFFFFF | |
643 | typedef ulong32 wchar_t; | |
644 | #define LTC_WCHAR_MAX 0xFFFFFFFF | |
846 | 645 | #endif |
847 | 646 | |
848 | 647 | int der_encode_utf8_string(const wchar_t *in, unsigned long inlen, |
851 | 650 | int der_decode_utf8_string(const unsigned char *in, unsigned long inlen, |
852 | 651 | wchar_t *out, unsigned long *outlen); |
853 | 652 | unsigned long der_utf8_charsize(const wchar_t c); |
854 | #ifdef LTC_SOURCE | |
855 | /* internal helper functions */ | |
856 | int der_utf8_valid_char(const wchar_t c); | |
857 | #endif /* LTC_SOURCE */ | |
858 | 653 | int der_length_utf8_string(const wchar_t *in, unsigned long noctets, unsigned long *outlen); |
859 | 654 | |
860 | 655 | |
905 | 700 | |
906 | 701 | int der_length_generalizedtime(const ltc_generalizedtime *gtime, unsigned long *outlen); |
907 | 702 | |
908 | #ifdef LTC_SOURCE | |
909 | /* internal helper functions */ | |
910 | /* SUBJECT PUBLIC KEY INFO */ | |
911 | int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen, | |
912 | unsigned int algorithm, const void* public_key, unsigned long public_key_len, | |
913 | ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len); | |
914 | ||
915 | int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen, | |
916 | unsigned int algorithm, void* public_key, unsigned long* public_key_len, | |
917 | ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len); | |
918 | #endif /* LTC_SOURCE */ | |
919 | ||
920 | 703 | #endif |
921 | 704 | |
922 | 705 | /* ref: $Format:%D$ */ |
0 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
1 | * | |
2 | * LibTomCrypt is a library that provides various cryptographic | |
3 | * algorithms in a highly modular and flexible manner. | |
4 | * | |
5 | * The library is free for all purposes without any express | |
6 | * guarantee it works. | |
7 | */ | |
8 | ||
9 | #include "tomcrypt.h" | |
10 | ||
11 | /* | |
12 | * Internal Macros | |
13 | */ | |
14 | ||
15 | #define LTC_PAD_MASK (0xF000U) | |
16 | ||
17 | /* | |
18 | * Internal Enums | |
19 | */ | |
20 | ||
21 | enum public_key_algorithms { | |
22 | PKA_RSA, | |
23 | PKA_DSA, | |
24 | PKA_EC, | |
25 | PKA_EC_PRIMEF | |
26 | }; | |
27 | ||
28 | /* | |
29 | * Internal Types | |
30 | */ | |
31 | ||
32 | typedef struct Oid { | |
33 | unsigned long OID[16]; | |
34 | /** Number of OID digits in use */ | |
35 | unsigned long OIDlen; | |
36 | } oid_st; | |
37 | ||
38 | typedef struct { | |
39 | int size; | |
40 | const char *name, *base, *prime; | |
41 | } ltc_dh_set_type; | |
42 | ||
43 | ||
44 | /* | |
45 | * Internal functions | |
46 | */ | |
47 | ||
48 | /* tomcrypt_hash.h */ | |
49 | ||
50 | /* a simple macro for making hash "process" functions */ | |
51 | #define HASH_PROCESS(func_name, compress_name, state_var, block_size) \ | |
52 | int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \ | |
53 | { \ | |
54 | unsigned long n; \ | |
55 | int err; \ | |
56 | LTC_ARGCHK(md != NULL); \ | |
57 | LTC_ARGCHK(in != NULL); \ | |
58 | if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \ | |
59 | return CRYPT_INVALID_ARG; \ | |
60 | } \ | |
61 | if ((md-> state_var .length + inlen) < md-> state_var .length) { \ | |
62 | return CRYPT_HASH_OVERFLOW; \ | |
63 | } \ | |
64 | while (inlen > 0) { \ | |
65 | if (md-> state_var .curlen == 0 && inlen >= block_size) { \ | |
66 | if ((err = compress_name (md, in)) != CRYPT_OK) { \ | |
67 | return err; \ | |
68 | } \ | |
69 | md-> state_var .length += block_size * 8; \ | |
70 | in += block_size; \ | |
71 | inlen -= block_size; \ | |
72 | } else { \ | |
73 | n = MIN(inlen, (block_size - md-> state_var .curlen)); \ | |
74 | XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \ | |
75 | md-> state_var .curlen += n; \ | |
76 | in += n; \ | |
77 | inlen -= n; \ | |
78 | if (md-> state_var .curlen == block_size) { \ | |
79 | if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) { \ | |
80 | return err; \ | |
81 | } \ | |
82 | md-> state_var .length += 8*block_size; \ | |
83 | md-> state_var .curlen = 0; \ | |
84 | } \ | |
85 | } \ | |
86 | } \ | |
87 | return CRYPT_OK; \ | |
88 | } | |
89 | ||
90 | ||
91 | /* tomcrypt_mac.h */ | |
92 | ||
93 | int ocb3_int_ntz(unsigned long x); | |
94 | void ocb3_int_xor_blocks(unsigned char *out, const unsigned char *block_a, const unsigned char *block_b, unsigned long block_len); | |
95 | ||
96 | ||
97 | /* tomcrypt_math.h */ | |
98 | ||
99 | #if !defined(DESC_DEF_ONLY) | |
100 | ||
101 | #define MP_DIGIT_BIT ltc_mp.bits_per_digit | |
102 | ||
103 | /* some handy macros */ | |
104 | #define mp_init(a) ltc_mp.init(a) | |
105 | #define mp_init_multi ltc_init_multi | |
106 | #define mp_clear(a) ltc_mp.deinit(a) | |
107 | #define mp_clear_multi ltc_deinit_multi | |
108 | #define mp_cleanup_multi ltc_cleanup_multi | |
109 | #define mp_init_copy(a, b) ltc_mp.init_copy(a, b) | |
110 | ||
111 | #define mp_neg(a, b) ltc_mp.neg(a, b) | |
112 | #define mp_copy(a, b) ltc_mp.copy(a, b) | |
113 | ||
114 | #define mp_set(a, b) ltc_mp.set_int(a, b) | |
115 | #define mp_set_int(a, b) ltc_mp.set_int(a, b) | |
116 | #define mp_get_int(a) ltc_mp.get_int(a) | |
117 | #define mp_get_digit(a, n) ltc_mp.get_digit(a, n) | |
118 | #define mp_get_digit_count(a) ltc_mp.get_digit_count(a) | |
119 | #define mp_cmp(a, b) ltc_mp.compare(a, b) | |
120 | #define mp_cmp_d(a, b) ltc_mp.compare_d(a, b) | |
121 | #define mp_count_bits(a) ltc_mp.count_bits(a) | |
122 | #define mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a) | |
123 | #define mp_2expt(a, b) ltc_mp.twoexpt(a, b) | |
124 | ||
125 | #define mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c) | |
126 | #define mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c) | |
127 | #define mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a) | |
128 | #define mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b) | |
129 | #define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c) | |
130 | ||
131 | #define mp_add(a, b, c) ltc_mp.add(a, b, c) | |
132 | #define mp_add_d(a, b, c) ltc_mp.addi(a, b, c) | |
133 | #define mp_sub(a, b, c) ltc_mp.sub(a, b, c) | |
134 | #define mp_sub_d(a, b, c) ltc_mp.subi(a, b, c) | |
135 | #define mp_mul(a, b, c) ltc_mp.mul(a, b, c) | |
136 | #define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c) | |
137 | #define mp_sqr(a, b) ltc_mp.sqr(a, b) | |
138 | #define mp_sqrtmod_prime(a, b, c) ltc_mp.sqrtmod_prime(a, b, c) | |
139 | #define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d) | |
140 | #define mp_div_2(a, b) ltc_mp.div_2(a, b) | |
141 | #define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c) | |
142 | #define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c) | |
143 | #define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c) | |
144 | #define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c) | |
145 | ||
146 | #define mp_addmod(a, b, c, d) ltc_mp.addmod(a, b, c, d) | |
147 | #define mp_submod(a, b, c, d) ltc_mp.submod(a, b, c, d) | |
148 | #define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d) | |
149 | #define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c) | |
150 | #define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c) | |
151 | ||
152 | #define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b) | |
153 | #define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b) | |
154 | #define mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c) | |
155 | #define mp_montgomery_free(a) ltc_mp.montgomery_deinit(a) | |
156 | ||
157 | #define mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d) | |
158 | #define mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, b, c) | |
159 | ||
160 | #define mp_iszero(a) (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO) | |
161 | #define mp_isodd(a) (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO) | |
162 | #define mp_exch(a, b) do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0) | |
163 | ||
164 | #define mp_tohex(a, b) mp_toradix(a, b, 16) | |
165 | ||
166 | #define mp_rand(a, b) ltc_mp.rand(a, b) | |
167 | ||
168 | #endif | |
169 | ||
170 | ||
171 | /* tomcrypt_misc.h */ | |
172 | ||
173 | void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned long len, int coz); | |
174 | ||
175 | ||
176 | /* tomcrypt_pk.h */ | |
177 | ||
178 | int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng); | |
179 | int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng); | |
180 | ||
181 | int pk_get_oid(int pk, oid_st *st); | |
182 | int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen); | |
183 | int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen); | |
184 | ||
185 | /* ---- DH Routines ---- */ | |
186 | #ifdef LTC_MDH | |
187 | extern const ltc_dh_set_type ltc_dh_sets[]; | |
188 | ||
189 | int dh_check_pubkey(const dh_key *key); | |
190 | #endif /* LTC_MDH */ | |
191 | ||
192 | /* ---- ECC Routines ---- */ | |
193 | #ifdef LTC_MECC | |
194 | int ecc_set_dp_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key); | |
195 | int ecc_copy_dp(const ecc_key *srckey, ecc_key *key); | |
196 | int ecc_set_dp_by_size(int size, ecc_key *key); | |
197 | ||
198 | /* low level functions */ | |
199 | ecc_point *ltc_ecc_new_point(void); | |
200 | void ltc_ecc_del_point(ecc_point *p); | |
201 | int ltc_ecc_set_point_xyz(ltc_mp_digit x, ltc_mp_digit y, ltc_mp_digit z, ecc_point *p); | |
202 | int ltc_ecc_copy_point(const ecc_point *src, ecc_point *dst); | |
203 | int ltc_ecc_is_point(const ltc_ecc_dp *dp, void *x, void *y); | |
204 | int ltc_ecc_is_point_at_infinity(const ecc_point *P, void *modulus, int *retval); | |
205 | int ltc_ecc_import_point(const unsigned char *in, unsigned long inlen, void *prime, void *a, void *b, void *x, void *y); | |
206 | int ltc_ecc_export_point(unsigned char *out, unsigned long *outlen, void *x, void *y, unsigned long size, int compressed); | |
207 | int ltc_ecc_verify_key(const ecc_key *key); | |
208 | ||
209 | /* point ops (mp == montgomery digit) */ | |
210 | #if !defined(LTC_MECC_ACCEL) || defined(LTM_DESC) || defined(GMP_DESC) | |
211 | /* R = 2P */ | |
212 | int ltc_ecc_projective_dbl_point(const ecc_point *P, ecc_point *R, void *ma, void *modulus, void *mp); | |
213 | ||
214 | /* R = P + Q */ | |
215 | int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_point *R, void *ma, void *modulus, void *mp); | |
216 | #endif | |
217 | ||
218 | #if defined(LTC_MECC_FP) | |
219 | /* optimized point multiplication using fixed point cache (HAC algorithm 14.117) */ | |
220 | int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *a, void *modulus, int map); | |
221 | ||
222 | /* functions for saving/loading/freeing/adding to fixed point cache */ | |
223 | int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen); | |
224 | int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen); | |
225 | void ltc_ecc_fp_free(void); | |
226 | int ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock); | |
227 | ||
228 | /* lock/unlock all points currently in fixed point cache */ | |
229 | void ltc_ecc_fp_tablelock(int lock); | |
230 | #endif | |
231 | ||
232 | /* R = kG */ | |
233 | int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *modulus, int map); | |
234 | ||
235 | #ifdef LTC_ECC_SHAMIR | |
236 | /* kA*A + kB*B = C */ | |
237 | int ltc_ecc_mul2add(const ecc_point *A, void *kA, | |
238 | const ecc_point *B, void *kB, | |
239 | ecc_point *C, | |
240 | void *ma, | |
241 | void *modulus); | |
242 | ||
243 | #ifdef LTC_MECC_FP | |
244 | /* Shamir's trick with optimized point multiplication using fixed point cache */ | |
245 | int ltc_ecc_fp_mul2add(const ecc_point *A, void *kA, | |
246 | const ecc_point *B, void *kB, | |
247 | ecc_point *C, | |
248 | void *ma, | |
249 | void *modulus); | |
250 | #endif | |
251 | ||
252 | #endif | |
253 | ||
254 | ||
255 | /* map P to affine from projective */ | |
256 | int ltc_ecc_map(ecc_point *P, void *modulus, void *mp); | |
257 | #endif /* LTC_MECC */ | |
258 | ||
259 | #ifdef LTC_MDSA | |
260 | int dsa_int_validate_xy(const dsa_key *key, int *stat); | |
261 | int dsa_int_validate_pqg(const dsa_key *key, int *stat); | |
262 | int dsa_int_validate_primes(const dsa_key *key, int *stat); | |
263 | #endif /* LTC_MDSA */ | |
264 | ||
265 | #ifdef LTC_DER | |
266 | /* DER handling */ | |
267 | int der_decode_custom_type_ex(const unsigned char *in, unsigned long inlen, | |
268 | ltc_asn1_list *root, | |
269 | ltc_asn1_list *list, unsigned long outlen, unsigned int flags); | |
270 | ||
271 | int der_encode_asn1_identifier(const ltc_asn1_list *id, unsigned char *out, unsigned long *outlen); | |
272 | int der_decode_asn1_identifier(const unsigned char *in, unsigned long *inlen, ltc_asn1_list *id); | |
273 | int der_length_asn1_identifier(const ltc_asn1_list *id, unsigned long *idlen); | |
274 | ||
275 | int der_encode_asn1_length(unsigned long len, unsigned char* out, unsigned long* outlen); | |
276 | int der_decode_asn1_length(const unsigned char* len, unsigned long* lenlen, unsigned long* outlen); | |
277 | int der_length_asn1_length(unsigned long len, unsigned long *outlen); | |
278 | ||
279 | int der_length_sequence_ex(const ltc_asn1_list *list, unsigned long inlen, | |
280 | unsigned long *outlen, unsigned long *payloadlen); | |
281 | ||
282 | extern const ltc_asn1_type der_asn1_tag_to_type_map[]; | |
283 | extern const unsigned long der_asn1_tag_to_type_map_sz; | |
284 | ||
285 | extern const int der_asn1_type_to_identifier_map[]; | |
286 | extern const unsigned long der_asn1_type_to_identifier_map_sz; | |
287 | ||
288 | int der_decode_sequence_multi_ex(const unsigned char *in, unsigned long inlen, unsigned int flags, ...); | |
289 | ||
290 | int der_teletex_char_encode(int c); | |
291 | int der_teletex_value_decode(int v); | |
292 | ||
293 | int der_utf8_valid_char(const wchar_t c); | |
294 | ||
295 | /* SUBJECT PUBLIC KEY INFO */ | |
296 | int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen, | |
297 | unsigned int algorithm, const void* public_key, unsigned long public_key_len, | |
298 | ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len); | |
299 | ||
300 | int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen, | |
301 | unsigned int algorithm, void* public_key, unsigned long* public_key_len, | |
302 | ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len); | |
303 | ||
304 | #endif /* LTC_DER */ | |
305 | ||
306 | /* tomcrypt_prng.h */ | |
307 | ||
308 | #define _LTC_PRNG_EXPORT(which) \ | |
309 | int which ## _export(unsigned char *out, unsigned long *outlen, prng_state *prng) \ | |
310 | { \ | |
311 | unsigned long len = which ## _desc.export_size; \ | |
312 | \ | |
313 | LTC_ARGCHK(prng != NULL); \ | |
314 | LTC_ARGCHK(out != NULL); \ | |
315 | LTC_ARGCHK(outlen != NULL); \ | |
316 | \ | |
317 | if (*outlen < len) { \ | |
318 | *outlen = len; \ | |
319 | return CRYPT_BUFFER_OVERFLOW; \ | |
320 | } \ | |
321 | \ | |
322 | if (which ## _read(out, len, prng) != len) { \ | |
323 | return CRYPT_ERROR_READPRNG; \ | |
324 | } \ | |
325 | \ | |
326 | *outlen = len; \ | |
327 | return CRYPT_OK; \ | |
328 | } | |
329 | ||
330 | ||
331 | /* ref: $Format:%D$ */ | |
332 | /* git commit: $Format:%H$ */ | |
333 | /* commit time: $Format:%ai$ */ |
39 | 39 | IV[16]; /* IV for CTR mode */ |
40 | 40 | |
41 | 41 | unsigned long pool_idx, /* current pool we will add to */ |
42 | pool0_len, /* length of 0'th pool */ | |
43 | wd; | |
44 | ||
42 | pool0_len; /* length of 0'th pool */ | |
43 | ulong64 wd; | |
45 | 44 | ulong64 reset_cnt; /* number of times we have reseeded */ |
46 | 45 | }; |
47 | 46 | #endif |
72 | 71 | #ifdef LTC_SOBER128 |
73 | 72 | struct sober128_prng sober128; |
74 | 73 | #endif |
75 | }; | |
74 | } u; | |
76 | 75 | short ready; /* ready flag 0-1 */ |
77 | 76 | LTC_MUTEX_TYPE(lock) /* lock */ |
78 | 77 | } prng_state; |
213 | 212 | int prng_is_valid(int idx); |
214 | 213 | LTC_MUTEX_PROTO(ltc_prng_mutex) |
215 | 214 | |
216 | #ifdef LTC_SOURCE | |
217 | /* internal helper functions */ | |
218 | #define _LTC_PRNG_EXPORT(which) \ | |
219 | int which ## _export(unsigned char *out, unsigned long *outlen, prng_state *prng) \ | |
220 | { \ | |
221 | unsigned long len = which ## _desc.export_size; \ | |
222 | \ | |
223 | LTC_ARGCHK(prng != NULL); \ | |
224 | LTC_ARGCHK(out != NULL); \ | |
225 | LTC_ARGCHK(outlen != NULL); \ | |
226 | \ | |
227 | if (*outlen < len) { \ | |
228 | *outlen = len; \ | |
229 | return CRYPT_BUFFER_OVERFLOW; \ | |
230 | } \ | |
231 | \ | |
232 | if (which ## _read(out, len, prng) != len) { \ | |
233 | return CRYPT_ERROR_READPRNG; \ | |
234 | } \ | |
235 | \ | |
236 | *outlen = len; \ | |
237 | return CRYPT_OK; \ | |
238 | } | |
239 | #endif | |
240 | ||
241 | 215 | /* Slow RNG you **might** be able to use to seed a PRNG with. Be careful as this |
242 | 216 | * might not work on all platforms as planned |
243 | 217 | */ |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_BLAKE2BMAC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_BLAKE2BMAC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_BLAKE2BMAC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | #include <stdarg.h> |
11 | 11 | |
12 | 12 | #ifdef LTC_BLAKE2BMAC |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_BLAKE2SMAC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_BLAKE2SMAC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_BLAKE2SMAC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | #include <stdarg.h> |
11 | 11 | |
12 | 12 | #ifdef LTC_BLAKE2SMAC |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file f9_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file f9_file.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file f9_init.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file f9_process.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file f9_process.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file hmac_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file hmac_file.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file hmac_init.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file hmac_memory.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file hmac_process.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file omac_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file omac_file.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file omac_init.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file omac_memory.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file omac_process.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pelican.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pelican_memory.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pmac_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pmac_file.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pmac_init.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pmac_memory.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pmac_ntz.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pmac_process.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pmac_shift_xor.c |
11 | 11 | * https://github.com/floodyberry/poly1305-donna |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_POLY1305 |
17 | 17 |
11 | 11 | * https://github.com/floodyberry/poly1305-donna |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_POLY1305 |
17 | 17 |
11 | 11 | * https://github.com/floodyberry/poly1305-donna |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_POLY1305 |
17 | 17 |
11 | 11 | * https://github.com/floodyberry/poly1305-donna |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | #include <stdarg.h> |
16 | 16 | |
17 | 17 | #ifdef LTC_POLY1305 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file xcbc_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file xcbc_file.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file xcbc_init.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file xcbc_process.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file xcbc_process.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ltc_ecc_fp_mulmod.c |
7 | 7 | */ |
8 | 8 | |
9 | 9 | #define DESC_DEF_ONLY |
10 | #include "tomcrypt.h" | |
10 | #include "tomcrypt_private.h" | |
11 | 11 | |
12 | 12 | #ifdef LTM_DESC |
13 | 13 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_MPI |
11 | 11 | #include <stdarg.h> |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file radix_to_bin.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #if defined(LTC_MDSA) || defined(LTC_MECC) |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #if defined(LTC_MRSA) || (!defined(LTC_NO_MATH) && !defined(LTC_NO_PRNGS)) |
11 | 11 |
7 | 7 | */ |
8 | 8 | |
9 | 9 | #define DESC_DEF_ONLY |
10 | #include "tomcrypt.h" | |
10 | #include "tomcrypt_private.h" | |
11 | 11 | |
12 | 12 | #ifdef TFM_DESC |
13 | 13 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file adler32.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file base16_decode.c |
20 | 20 | /** |
21 | 21 | Base16 decode a string |
22 | 22 | @param in The Base16 string to decode |
23 | @param inlen The length of the Base16 data | |
23 | 24 | @param out [out] The destination of the binary decoded data |
24 | 25 | @param outlen [in/out] The max size and resulting size of the decoded data |
25 | 26 | @return CRYPT_OK if successful |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file base16_encode.c |
21 | 21 | @param inlen The length of the input buffer |
22 | 22 | @param out [out] The destination of the Base16 encoded data |
23 | 23 | @param outlen [in/out] The max size and resulting size of the encoded data |
24 | @param caps Output 'a-f' on 0 and 'A-F' otherwise. | |
24 | @param options Output 'a-f' on 0 and 'A-F' otherwise. | |
25 | 25 | @return CRYPT_OK if successful |
26 | 26 | */ |
27 | 27 | int base16_encode(const unsigned char *in, unsigned long inlen, |
28 | 28 | char *out, unsigned long *outlen, |
29 | int caps) | |
29 | unsigned int options) | |
30 | 30 | { |
31 | 31 | unsigned long i, x; |
32 | 32 | const char *alphabet; |
51 | 51 | x--; |
52 | 52 | *outlen = x; /* returning the length without terminating NUL */ |
53 | 53 | |
54 | if (caps == 0) alphabet = alphabets[0]; | |
54 | if (options == 0) alphabet = alphabets[0]; | |
55 | 55 | else alphabet = alphabets[1]; |
56 | 56 | |
57 | 57 | for (i = 0; i < x; i += 2) { |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_BASE32 |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_BASE32 |
12 | 12 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file base64_decode.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file base64_encode.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file burn_stack.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file compare_testvector.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file copy_or_zeromem.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crc32.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt.c |
134 | 134 | #if defined(LTC_SALSA20) |
135 | 135 | " Salsa20\n" |
136 | 136 | #endif |
137 | #if defined(LTC_XSALSA20) | |
138 | " XSalsa20\n" | |
139 | #endif | |
137 | 140 | #if defined(LTC_SOSEMANUK) |
138 | 141 | " Sosemanuk\n" |
139 | 142 | #endif |
349 | 352 | #if defined(LTC_MDSA) |
350 | 353 | " DSA\n" |
351 | 354 | #endif |
352 | #if defined(LTC_MKAT) | |
353 | " Katja\n" | |
354 | #endif | |
355 | 355 | #if defined(LTC_PK_MAX_RETRIES) |
356 | 356 | " "NAME_VALUE(LTC_PK_MAX_RETRIES)"\n" |
357 | 357 | #endif |
514 | 514 | " LTC_MECC_ACCEL " |
515 | 515 | #endif |
516 | 516 | #if defined(LTC_MECC_FP) |
517 | " LTC_MECC_FP " | |
517 | " LTC_MECC_FP " | |
518 | 518 | #endif |
519 | 519 | #if defined(LTC_ECC_SHAMIR) |
520 | " LTC_ECC_SHAMIR " | |
520 | " LTC_ECC_SHAMIR " | |
521 | #endif | |
522 | #if defined(LTC_CLOCK_GETTIME) | |
523 | " LTC_CLOCK_GETTIME " | |
521 | 524 | #endif |
522 | 525 | "\n" |
523 | 526 | ; |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_argchk.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_cipher_descriptor.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_cipher_is_valid.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_constants.c |
95 | 95 | {"LTC_MRSA", 0}, |
96 | 96 | #endif |
97 | 97 | |
98 | #ifdef LTC_MKAT | |
99 | {"LTC_MKAT", 1}, | |
100 | _C_STRINGIFY(MIN_KAT_SIZE), | |
101 | _C_STRINGIFY(MAX_KAT_SIZE), | |
102 | #else | |
103 | {"LTC_MKAT", 0}, | |
104 | #endif | |
105 | ||
106 | 98 | #ifdef LTC_MECC |
107 | 99 | {"LTC_MECC", 1}, |
108 | 100 | _C_STRINGIFY(ECC_BUF_SIZE), |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_find_cipher.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_find_cipher_any.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_find_cipher_id.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_find_hash.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_find_hash_any.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_find_hash_id.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_find_hash_oid.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_find_prng.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_hash_descriptor.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_hash_is_valid.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_inits.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /* Initialize ltc_mp to nulls, to force allocation on all platforms, including macOS. */ |
11 | 11 | ltc_math_descriptor ltc_mp = { 0 }; |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_prng_descriptor.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_prng_is_valid.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_PRNG_ENABLE_LTC_RNG |
11 | 11 | unsigned long (*ltc_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file crypt_register_all_ciphers.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file crypt_register_all_hashes.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file crypt_register_all_prngs.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_register_cipher.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_register_hash.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_register_prng.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_sizes.c |
247 | 247 | _SZ_STRINGIFY_T(ltc_ecc_curve), |
248 | 248 | _SZ_STRINGIFY_T(ecc_point), |
249 | 249 | _SZ_STRINGIFY_T(ecc_key), |
250 | #endif | |
251 | #ifdef LTC_MKAT | |
252 | _SZ_STRINGIFY_T(katja_key), | |
253 | 250 | #endif |
254 | 251 | |
255 | 252 | /* DER handling */ |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_unregister_cipher.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_unregister_hash.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file crypt_unregister_prng.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file error_to_string.c |
10 | 10 | #include <stdio.h> |
11 | 11 | #include <stdlib.h> |
12 | 12 | |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_HKDF |
16 | 16 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file mem_neq.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_PADDING |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_PADDING |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_DER |
11 | 11 | static const oid_st rsa_oid = { |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen) |
12 | 12 | { |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_5_1.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_5_2.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file zeromem.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cbc_decrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cbc_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cbc_encrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cbc_getiv.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cbc_setiv.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cbc_start.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cfb_decrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cfb_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cfb_encrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cfb_getiv.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cfb_setiv.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file cfb_start.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ctr_decrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ctr_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ctr_encrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ctr_getiv.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ctr_setiv.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ctr_start.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ecb_decrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ecb_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ecb_encrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ecb_start.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ofb_decrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ofb_done.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ofb_encrypt.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ofb_getiv.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ofb_setiv.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file ofb_start.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_bit_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_bit_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_bit_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_bit_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_bit_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_boolean.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_boolean.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_boolean.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_choice.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_custom_type.c |
189 | 189 | } |
190 | 190 | } else { |
191 | 191 | /* calc length of length */ |
192 | if ((err = der_length_asn1_length(y, &x)) != CRYPT_OK) { | |
192 | if ((err = der_length_asn1_length(y - id_len, &x)) != CRYPT_OK) { | |
193 | 193 | goto LBL_ERR; |
194 | 194 | } |
195 | 195 | if (payloadlen != NULL) { |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_asn1_maps.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_asn1_identifier.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_asn1_length.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_asn1_identifier.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_asn1_length.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_asn1_identifier.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_asn1_length.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_generalizedtime.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_utctime.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_utctime.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_ia5_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_ia5_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_ia5_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_integer.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_integer.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_integer.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_object_identifier.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_object_identifier.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_object_identifier.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_octet_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_octet_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_octet_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_printable_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_printable_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_printable_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_sequence_flexi.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | #include <stdarg.h> |
10 | 10 | |
11 | 11 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_sequence.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_sequence_free.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_sequence_shrink.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_set.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_setof.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_short_integer.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_short_integer.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_short_integer.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_teletex_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_teletex_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_utctime.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_utctime.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_utctime.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_decode_utf8_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_encode_utf8_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file der_length_utf8_string.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file x509_decode_subject_public_key_info.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file x509_encode_subject_public_key_info.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDH |
12 | 12 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_decrypt_key.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_encrypt_key.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_export.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_free.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_make_key.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_generate_pqg.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_import.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_make_key.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDSA |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | |
11 | 11 | #ifdef LTC_MDSA |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_shared_secret.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_sign_hash.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_verify_hash.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file dsa_verify_key.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_ansi_x963_export.c |
23 | 23 | */ |
24 | 24 | int ecc_ansi_x963_export(const ecc_key *key, unsigned char *out, unsigned long *outlen) |
25 | 25 | { |
26 | unsigned char buf[ECC_BUF_SIZE]; | |
27 | unsigned long numlen, xlen, ylen; | |
28 | ||
29 | LTC_ARGCHK(key != NULL); | |
30 | LTC_ARGCHK(out != NULL); | |
31 | LTC_ARGCHK(outlen != NULL); | |
32 | ||
33 | numlen = key->dp.size; | |
34 | xlen = mp_unsigned_bin_size(key->pubkey.x); | |
35 | ylen = mp_unsigned_bin_size(key->pubkey.y); | |
36 | ||
37 | if (xlen > numlen || ylen > numlen || sizeof(buf) < numlen) { | |
38 | return CRYPT_BUFFER_OVERFLOW; | |
39 | } | |
40 | ||
41 | if (*outlen < (1 + 2*numlen)) { | |
42 | *outlen = 1 + 2*numlen; | |
43 | return CRYPT_BUFFER_OVERFLOW; | |
44 | } | |
45 | ||
46 | /* store byte 0x04 */ | |
47 | out[0] = 0x04; | |
48 | ||
49 | /* pad and store x */ | |
50 | zeromem(buf, sizeof(buf)); | |
51 | mp_to_unsigned_bin(key->pubkey.x, buf + (numlen - xlen)); | |
52 | XMEMCPY(out+1, buf, numlen); | |
53 | ||
54 | /* pad and store y */ | |
55 | zeromem(buf, sizeof(buf)); | |
56 | mp_to_unsigned_bin(key->pubkey.y, buf + (numlen - ylen)); | |
57 | XMEMCPY(out+1+numlen, buf, numlen); | |
58 | ||
59 | *outlen = 1 + 2*numlen; | |
60 | return CRYPT_OK; | |
26 | return ecc_get_key(out, outlen, PK_PUBLIC, key); | |
61 | 27 | } |
62 | 28 | |
63 | 29 | #endif |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_ansi_x963_import.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_decrypt_key.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_encrypt_key.c |
41 | 41 | LTC_ARGCHK(out != NULL); |
42 | 42 | LTC_ARGCHK(outlen != NULL); |
43 | 43 | LTC_ARGCHK(key != NULL); |
44 | ||
45 | /* check that wprng/cipher/hash are not invalid */ | |
46 | if ((err = prng_is_valid(wprng)) != CRYPT_OK) { | |
47 | return err; | |
48 | } | |
49 | 44 | |
50 | 45 | if ((err = hash_is_valid(hash)) != CRYPT_OK) { |
51 | 46 | return err; |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_export.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_free.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
0 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
1 | * | |
2 | * LibTomCrypt is a library that provides various cryptographic | |
3 | * algorithms in a highly modular and flexible manner. | |
4 | * | |
5 | * The library is free for all purposes without any express | |
6 | * guarantee it works. | |
7 | */ | |
8 | ||
9 | #include "tomcrypt_private.h" | |
10 | ||
11 | #ifdef LTC_MECC | |
12 | ||
13 | /** Extract OID as a string from ECC key | |
14 | @param out [out] destination buffer | |
15 | @param outlen [in/out] Length of destination buffer and final output size (without terminating NUL byte) | |
16 | @param key The ECC key | |
17 | Return CRYPT_OK on success | |
18 | */ | |
19 | ||
20 | int ecc_get_oid_str(char *out, unsigned long *outlen, const ecc_key *key) | |
21 | { | |
22 | LTC_ARGCHK(key != NULL); | |
23 | ||
24 | return pk_oid_num_to_str(key->dp.oid, key->dp.oidlen, out, outlen); | |
25 | } | |
26 | ||
27 | #endif | |
28 | ||
29 | /* ref: $Format:%D$ */ | |
30 | /* git commit: $Format:%H$ */ | |
31 | /* commit time: $Format:%ai$ */ |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_get_size.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_import.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 | |
148 | 148 | goto success; |
149 | 149 | } |
150 | 150 | |
151 | /* ### 5. backward compatibility - try to load old-DER format */ | |
152 | ||
153 | if ((err = ecc_import(in, inlen, key)) != CRYPT_OK) { goto error; } | |
151 | /* ### 5. all attempts failed */ | |
152 | goto error; | |
154 | 153 | |
155 | 154 | success: |
156 | 155 | err = CRYPT_OK; |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 | |
114 | 114 | key = XMALLOC(u * c); |
115 | 115 | I = XMALLOC(Plen + Slen); |
116 | 116 | if (key == NULL || I == NULL) goto DONE; |
117 | zeromem(key, u * c); | |
117 | 118 | |
118 | 119 | for (i = 0; i < v; i++) D[i] = purpose; /* D - diversifier */ |
119 | 120 | for (i = 0; i < Slen; i++) I[i] = salt[i % saltlen]; |
228 | 229 | pad = dec_data[enc_size-1]; |
229 | 230 | if (pad < 1 || pad > blklen) goto LBL_ERROR; |
230 | 231 | *dec_size = enc_size - pad; |
231 | return CRYPT_OK; | |
232 | err = CRYPT_OK; | |
233 | goto LBL_DONE; | |
232 | 234 | } |
233 | 235 | |
234 | 236 | LBL_ERROR: |
237 | err = CRYPT_INVALID_ARG; | |
238 | LBL_DONE: | |
235 | 239 | zeromem(key_iv, sizeof(key_iv)); |
236 | 240 | if (pw) { zeromem(pw, pwlen); XFREE(pw); } |
237 | return CRYPT_INVALID_ARG; | |
241 | return err; | |
238 | 242 | } |
239 | 243 | |
240 | 244 | static int _pbes2_pbkdf2_decrypt(const unsigned char *enc_data, unsigned long enc_size, |
569 | 573 | /* load private key value 'k' */ |
570 | 574 | len = lpri->size; |
571 | 575 | if ((err = der_decode_sequence_flexi(lpri->data, &len, &p)) == CRYPT_OK) { |
572 | err = CRYPT_INVALID_PACKET; | |
573 | 576 | if (p->type == LTC_ASN1_SEQUENCE && |
574 | 577 | p->child && p->child->type == LTC_ASN1_INTEGER && |
575 | 578 | p->child->next && p->child->next->type == LTC_ASN1_OCTET_STRING) { |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_MECC |
11 | 11 | |
27 | 27 | |
28 | 28 | len = inlen; |
29 | 29 | if ((err = der_decode_sequence_flexi(in, &len, &decoded_list)) == CRYPT_OK) { |
30 | err = CRYPT_ERROR; | |
30 | 31 | l = decoded_list; |
31 | 32 | if (l->type == LTC_ASN1_SEQUENCE && |
32 | 33 | l->child && l->child->type == LTC_ASN1_SEQUENCE) { |
33 | err = CRYPT_ERROR; | |
34 | 34 | l = l->child->child; |
35 | 35 | while (l) { |
36 | 36 | if (l->type == LTC_ASN1_SEQUENCE && l->data && |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_make_key.c |
48 | 48 | LTC_ARGCHK(key != NULL); |
49 | 49 | LTC_ARGCHK(key->dp.size > 0); |
50 | 50 | |
51 | /* good prng? */ | |
52 | if ((err = prng_is_valid(wprng)) != CRYPT_OK) { | |
53 | return err; | |
54 | } | |
55 | ||
56 | 51 | /* ECC key pair generation according to FIPS-186-4 (B.4.2 Key Pair Generation by Testing Candidates): |
57 | 52 | * the generated private key k should be the range [1, order-1] |
58 | 53 | * a/ N = bitlen(order) |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 | |
23 | 23 | a = key->dp.A; |
24 | 24 | b = key->dp.B; |
25 | 25 | |
26 | if (type == PK_PRIVATE && inlen <= (unsigned long)key->dp.size) { | |
26 | if (type == PK_PRIVATE) { | |
27 | 27 | /* load private key */ |
28 | 28 | if ((err = mp_read_unsigned_bin(key->k, (unsigned char *)in, inlen)) != CRYPT_OK) { |
29 | 29 | goto error; |
30 | 30 | } |
31 | if (mp_iszero(key->k)) { | |
31 | if (mp_iszero(key->k) || (mp_cmp(key->k, key->dp.order) != LTC_MP_LT)) { | |
32 | 32 | err = CRYPT_INVALID_PACKET; |
33 | 33 | goto error; |
34 | 34 | } |
35 | 35 | /* compute public key */ |
36 | 36 | if ((err = ltc_mp.ecc_ptmul(key->k, &key->dp.base, &key->pubkey, a, prime, 1)) != CRYPT_OK) { goto error; } |
37 | key->type = type; | |
38 | 37 | } |
39 | 38 | else if (type == PK_PUBLIC) { |
40 | 39 | /* load public key */ |
41 | 40 | if ((err = ltc_ecc_import_point(in, inlen, prime, a, b, key->pubkey.x, key->pubkey.y)) != CRYPT_OK) { goto error; } |
42 | 41 | if ((err = mp_set(key->pubkey.z, 1)) != CRYPT_OK) { goto error; } |
43 | key->type = type; | |
44 | 42 | } |
45 | 43 | else { |
46 | 44 | err = CRYPT_INVALID_PACKET; |
52 | 50 | goto error; |
53 | 51 | } |
54 | 52 | |
53 | key->type = type; | |
55 | 54 | return CRYPT_OK; |
56 | 55 | |
57 | 56 | error: |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_shared_secret.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 | |
33 | 33 | /* is this a private key? */ |
34 | 34 | if (key->type != PK_PRIVATE) { |
35 | 35 | return CRYPT_PK_NOT_PRIVATE; |
36 | } | |
37 | ||
38 | if ((err = prng_is_valid(wprng)) != CRYPT_OK) { | |
39 | return err; | |
40 | 36 | } |
41 | 37 | |
42 | 38 | /* init the bignums */ |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ecc_sizes.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_MECC |
12 | 12 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ltc_ecc_map.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ltc_ecc_mul2add.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ltc_ecc_mulmod.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ltc_ecc_mulmod_timing.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ltc_ecc_points.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file ltc_ecc_projective_add_point.c |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /* ### Point doubling in Jacobian coordinate system ### |
12 | 12 | * |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /* origin of this code - OLPC */ |
12 | 12 |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_1_i2osp.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_1_mgf1.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_1_oaep_decode.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_1_oaep_encode.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_1_os2ip.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_1_pss_decode.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file pkcs_1_pss_encode.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** @file pkcs_1_v1_5_decode.c |
11 | 11 | * |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /*! \file pkcs_1_v1_5_encode.c |
11 | 11 | * |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_decrypt_key.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_encrypt_key.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_export.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_exptmod.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_free.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_get_size.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_import.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_import_pkcs8.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_import.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_make_key.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | |
11 | 11 | #ifdef LTC_MRSA |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_sign_hash.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_sign_saltlen_get.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file rsa_verify_hash.c |
10 | 10 | * http://bxr.su/OpenBSD/lib/libc/crypt/arc4random.c |
11 | 11 | */ |
12 | 12 | |
13 | #include "tomcrypt.h" | |
13 | #include "tomcrypt_private.h" | |
14 | 14 | |
15 | 15 | #ifdef LTC_CHACHA20_PRNG |
16 | 16 | |
37 | 37 | { |
38 | 38 | LTC_ARGCHK(prng != NULL); |
39 | 39 | prng->ready = 0; |
40 | XMEMSET(&prng->chacha.ent, 0, sizeof(prng->chacha.ent)); | |
41 | prng->chacha.idx = 0; | |
40 | XMEMSET(&prng->u.chacha.ent, 0, sizeof(prng->u.chacha.ent)); | |
41 | prng->u.chacha.idx = 0; | |
42 | 42 | LTC_MUTEX_INIT(&prng->lock) |
43 | 43 | return CRYPT_OK; |
44 | 44 | } |
63 | 63 | LTC_MUTEX_LOCK(&prng->lock); |
64 | 64 | if (prng->ready) { |
65 | 65 | /* chacha20_prng_ready() was already called, do "rekey" operation */ |
66 | if ((err = chacha_keystream(&prng->chacha.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; | |
66 | if ((err = chacha_keystream(&prng->u.chacha.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; | |
67 | 67 | for(i = 0; i < inlen; i++) buf[i % sizeof(buf)] ^= in[i]; |
68 | 68 | /* key 32 bytes, 20 rounds */ |
69 | if ((err = chacha_setup(&prng->chacha.s, buf, 32, 20)) != CRYPT_OK) goto LBL_UNLOCK; | |
69 | if ((err = chacha_setup(&prng->u.chacha.s, buf, 32, 20)) != CRYPT_OK) goto LBL_UNLOCK; | |
70 | 70 | /* iv 8 bytes */ |
71 | if ((err = chacha_ivctr64(&prng->chacha.s, buf + 32, 8, 0)) != CRYPT_OK) goto LBL_UNLOCK; | |
71 | if ((err = chacha_ivctr64(&prng->u.chacha.s, buf + 32, 8, 0)) != CRYPT_OK) goto LBL_UNLOCK; | |
72 | 72 | /* clear KEY + IV */ |
73 | 73 | zeromem(buf, sizeof(buf)); |
74 | 74 | } |
75 | 75 | else { |
76 | 76 | /* chacha20_prng_ready() was not called yet, add entropy to ent buffer */ |
77 | while (inlen--) prng->chacha.ent[prng->chacha.idx++ % sizeof(prng->chacha.ent)] ^= *in++; | |
77 | while (inlen--) prng->u.chacha.ent[prng->u.chacha.idx++ % sizeof(prng->u.chacha.ent)] ^= *in++; | |
78 | 78 | } |
79 | 79 | err = CRYPT_OK; |
80 | 80 | LBL_UNLOCK: |
96 | 96 | LTC_MUTEX_LOCK(&prng->lock); |
97 | 97 | if (prng->ready) { err = CRYPT_OK; goto LBL_UNLOCK; } |
98 | 98 | /* key 32 bytes, 20 rounds */ |
99 | if ((err = chacha_setup(&prng->chacha.s, prng->chacha.ent, 32, 20)) != CRYPT_OK) goto LBL_UNLOCK; | |
99 | if ((err = chacha_setup(&prng->u.chacha.s, prng->u.chacha.ent, 32, 20)) != CRYPT_OK) goto LBL_UNLOCK; | |
100 | 100 | /* iv 8 bytes */ |
101 | if ((err = chacha_ivctr64(&prng->chacha.s, prng->chacha.ent + 32, 8, 0)) != CRYPT_OK) goto LBL_UNLOCK; | |
102 | XMEMSET(&prng->chacha.ent, 0, sizeof(prng->chacha.ent)); | |
103 | prng->chacha.idx = 0; | |
101 | if ((err = chacha_ivctr64(&prng->u.chacha.s, prng->u.chacha.ent + 32, 8, 0)) != CRYPT_OK) goto LBL_UNLOCK; | |
102 | XMEMSET(&prng->u.chacha.ent, 0, sizeof(prng->u.chacha.ent)); | |
103 | prng->u.chacha.idx = 0; | |
104 | 104 | prng->ready = 1; |
105 | 105 | LBL_UNLOCK: |
106 | 106 | LTC_MUTEX_UNLOCK(&prng->lock); |
119 | 119 | if (outlen == 0 || prng == NULL || out == NULL) return 0; |
120 | 120 | LTC_MUTEX_LOCK(&prng->lock); |
121 | 121 | if (!prng->ready) { outlen = 0; goto LBL_UNLOCK; } |
122 | if (chacha_keystream(&prng->chacha.s, out, outlen) != CRYPT_OK) outlen = 0; | |
122 | if (chacha_keystream(&prng->u.chacha.s, out, outlen) != CRYPT_OK) outlen = 0; | |
123 | 123 | LBL_UNLOCK: |
124 | 124 | LTC_MUTEX_UNLOCK(&prng->lock); |
125 | 125 | return outlen; |
136 | 136 | LTC_ARGCHK(prng != NULL); |
137 | 137 | LTC_MUTEX_LOCK(&prng->lock); |
138 | 138 | prng->ready = 0; |
139 | err = chacha_done(&prng->chacha.s); | |
139 | err = chacha_done(&prng->u.chacha.s); | |
140 | 140 | LTC_MUTEX_UNLOCK(&prng->lock); |
141 | 141 | LTC_MUTEX_DESTROY(&prng->lock); |
142 | 142 | return err; |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
9 | ||
8 | #include "tomcrypt_private.h" | |
9 | ||
10 | #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED | |
10 | 11 | #if defined(_WIN32) |
11 | 12 | #include <windows.h> |
13 | #elif defined(LTC_CLOCK_GETTIME) | |
14 | #include <time.h> /* struct timespec + clock_gettime */ | |
12 | 15 | #else |
13 | #include <sys/time.h> | |
16 | #include <sys/time.h> /* struct timeval + gettimeofday */ | |
17 | #endif | |
14 | 18 | #endif |
15 | 19 | |
16 | 20 | /** |
59 | 63 | int x; |
60 | 64 | unsigned char *IV; |
61 | 65 | /* update IV */ |
62 | IV = prng->fortuna.IV; | |
66 | IV = prng->u.fortuna.IV; | |
63 | 67 | for (x = 0; x < 16; x++) { |
64 | 68 | IV[x] = (IV[x] + 1) & 255; |
65 | 69 | if (IV[x] != 0) break; |
102 | 106 | int err, x; |
103 | 107 | |
104 | 108 | #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED |
105 | unsigned long now = _fortuna_current_time(); | |
106 | if (now == prng->fortuna.wd) | |
109 | ulong64 now = _fortuna_current_time(); | |
110 | if (now == prng->u.fortuna.wd) | |
107 | 111 | return CRYPT_OK; |
108 | 112 | #else |
109 | if (++prng->fortuna.wd < LTC_FORTUNA_WD) | |
113 | if (++prng->u.fortuna.wd < LTC_FORTUNA_WD) | |
110 | 114 | return CRYPT_OK; |
111 | 115 | #endif |
112 | 116 | |
113 | 117 | /* new K == LTC_SHA256(K || s) where s == LTC_SHA256(P0) || LTC_SHA256(P1) ... */ |
114 | 118 | sha256_init(&md); |
115 | if ((err = sha256_process(&md, prng->fortuna.K, 32)) != CRYPT_OK) { | |
119 | if ((err = sha256_process(&md, prng->u.fortuna.K, 32)) != CRYPT_OK) { | |
116 | 120 | sha256_done(&md, tmp); |
117 | 121 | return err; |
118 | 122 | } |
119 | 123 | |
120 | reset_cnt = prng->fortuna.reset_cnt + 1; | |
124 | reset_cnt = prng->u.fortuna.reset_cnt + 1; | |
121 | 125 | |
122 | 126 | for (x = 0; x < LTC_FORTUNA_POOLS; x++) { |
123 | 127 | if (x == 0 || ((reset_cnt >> (x-1)) & 1) == 0) { |
124 | 128 | /* terminate this hash */ |
125 | if ((err = sha256_done(&prng->fortuna.pool[x], tmp)) != CRYPT_OK) { | |
129 | if ((err = sha256_done(&prng->u.fortuna.pool[x], tmp)) != CRYPT_OK) { | |
126 | 130 | sha256_done(&md, tmp); |
127 | 131 | return err; |
128 | 132 | } |
132 | 136 | return err; |
133 | 137 | } |
134 | 138 | /* reset this pool */ |
135 | if ((err = sha256_init(&prng->fortuna.pool[x])) != CRYPT_OK) { | |
139 | if ((err = sha256_init(&prng->u.fortuna.pool[x])) != CRYPT_OK) { | |
136 | 140 | sha256_done(&md, tmp); |
137 | 141 | return err; |
138 | 142 | } |
142 | 146 | } |
143 | 147 | |
144 | 148 | /* finish key */ |
145 | if ((err = sha256_done(&md, prng->fortuna.K)) != CRYPT_OK) { | |
146 | return err; | |
147 | } | |
148 | if ((err = rijndael_setup(prng->fortuna.K, 32, 0, &prng->fortuna.skey)) != CRYPT_OK) { | |
149 | if ((err = sha256_done(&md, prng->u.fortuna.K)) != CRYPT_OK) { | |
150 | return err; | |
151 | } | |
152 | if ((err = rijndael_setup(prng->u.fortuna.K, 32, 0, &prng->u.fortuna.skey)) != CRYPT_OK) { | |
149 | 153 | return err; |
150 | 154 | } |
151 | 155 | _fortuna_update_iv(prng); |
152 | 156 | |
153 | 157 | /* reset/update internals */ |
154 | prng->fortuna.pool0_len = 0; | |
158 | prng->u.fortuna.pool0_len = 0; | |
155 | 159 | #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED |
156 | prng->fortuna.wd = now; | |
160 | prng->u.fortuna.wd = now; | |
157 | 161 | #else |
158 | prng->fortuna.wd = 0; | |
159 | #endif | |
160 | prng->fortuna.reset_cnt = reset_cnt; | |
162 | prng->u.fortuna.wd = 0; | |
163 | #endif | |
164 | prng->u.fortuna.reset_cnt = reset_cnt; | |
161 | 165 | |
162 | 166 | |
163 | 167 | #ifdef LTC_CLEAN_STACK |
185 | 189 | LTC_MUTEX_LOCK(&prng->lock); |
186 | 190 | /* new K = LTC_SHA256(K || in) */ |
187 | 191 | sha256_init(&md); |
188 | if ((err = sha256_process(&md, prng->fortuna.K, 32)) != CRYPT_OK) { | |
192 | if ((err = sha256_process(&md, prng->u.fortuna.K, 32)) != CRYPT_OK) { | |
189 | 193 | sha256_done(&md, tmp); |
190 | 194 | goto LBL_UNLOCK; |
191 | 195 | } |
194 | 198 | goto LBL_UNLOCK; |
195 | 199 | } |
196 | 200 | /* finish key */ |
197 | if ((err = sha256_done(&md, prng->fortuna.K)) != CRYPT_OK) { | |
201 | if ((err = sha256_done(&md, prng->u.fortuna.K)) != CRYPT_OK) { | |
198 | 202 | goto LBL_UNLOCK; |
199 | 203 | } |
200 | 204 | _fortuna_update_iv(prng); |
223 | 227 | |
224 | 228 | /* initialize the pools */ |
225 | 229 | for (x = 0; x < LTC_FORTUNA_POOLS; x++) { |
226 | if ((err = sha256_init(&prng->fortuna.pool[x])) != CRYPT_OK) { | |
230 | if ((err = sha256_init(&prng->u.fortuna.pool[x])) != CRYPT_OK) { | |
227 | 231 | for (y = 0; y < x; y++) { |
228 | sha256_done(&prng->fortuna.pool[y], tmp); | |
232 | sha256_done(&prng->u.fortuna.pool[y], tmp); | |
229 | 233 | } |
230 | 234 | return err; |
231 | 235 | } |
232 | 236 | } |
233 | prng->fortuna.pool_idx = prng->fortuna.pool0_len = prng->fortuna.wd = 0; | |
234 | prng->fortuna.reset_cnt = 0; | |
237 | prng->u.fortuna.pool_idx = prng->u.fortuna.pool0_len = prng->u.fortuna.wd = 0; | |
238 | prng->u.fortuna.reset_cnt = 0; | |
235 | 239 | |
236 | 240 | /* reset bufs */ |
237 | zeromem(prng->fortuna.K, 32); | |
238 | if ((err = rijndael_setup(prng->fortuna.K, 32, 0, &prng->fortuna.skey)) != CRYPT_OK) { | |
241 | zeromem(prng->u.fortuna.K, 32); | |
242 | if ((err = rijndael_setup(prng->u.fortuna.K, 32, 0, &prng->u.fortuna.skey)) != CRYPT_OK) { | |
239 | 243 | for (x = 0; x < LTC_FORTUNA_POOLS; x++) { |
240 | sha256_done(&prng->fortuna.pool[x], tmp); | |
244 | sha256_done(&prng->u.fortuna.pool[x], tmp); | |
241 | 245 | } |
242 | 246 | return err; |
243 | 247 | } |
244 | zeromem(prng->fortuna.IV, 16); | |
248 | zeromem(prng->u.fortuna.IV, 16); | |
245 | 249 | |
246 | 250 | LTC_MUTEX_INIT(&prng->lock) |
247 | 251 | |
262 | 266 | tmp[0] = (unsigned char)source; |
263 | 267 | tmp[1] = (unsigned char)inlen; |
264 | 268 | |
265 | if ((err = sha256_process(&prng->fortuna.pool[pool], tmp, 2)) != CRYPT_OK) { | |
266 | return err; | |
267 | } | |
268 | if ((err = sha256_process(&prng->fortuna.pool[pool], in, inlen)) != CRYPT_OK) { | |
269 | if ((err = sha256_process(&prng->u.fortuna.pool[pool], tmp, 2)) != CRYPT_OK) { | |
270 | return err; | |
271 | } | |
272 | if ((err = sha256_process(&prng->u.fortuna.pool[pool], in, inlen)) != CRYPT_OK) { | |
269 | 273 | return err; |
270 | 274 | } |
271 | 275 | if (pool == 0) { |
272 | prng->fortuna.pool0_len += inlen; | |
276 | prng->u.fortuna.pool0_len += inlen; | |
273 | 277 | } |
274 | 278 | return CRYPT_OK; /* success */ |
275 | 279 | } |
319 | 323 | |
320 | 324 | LTC_MUTEX_LOCK(&prng->lock); |
321 | 325 | |
322 | err = _fortuna_add(0, prng->fortuna.pool_idx, in, inlen, prng); | |
326 | err = _fortuna_add(0, prng->u.fortuna.pool_idx, in, inlen, prng); | |
323 | 327 | |
324 | 328 | if (err == CRYPT_OK) { |
325 | ++(prng->fortuna.pool_idx); | |
326 | prng->fortuna.pool_idx %= LTC_FORTUNA_POOLS; | |
329 | ++(prng->u.fortuna.pool_idx); | |
330 | prng->u.fortuna.pool_idx %= LTC_FORTUNA_POOLS; | |
327 | 331 | } |
328 | 332 | |
329 | 333 | LTC_MUTEX_UNLOCK(&prng->lock); |
345 | 349 | /* make sure the reseed doesn't fail because |
346 | 350 | * of the chosen rate limit */ |
347 | 351 | #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED |
348 | prng->fortuna.wd = _fortuna_current_time() - 1; | |
352 | prng->u.fortuna.wd = _fortuna_current_time() - 1; | |
349 | 353 | #else |
350 | prng->fortuna.wd = LTC_FORTUNA_WD; | |
354 | prng->u.fortuna.wd = LTC_FORTUNA_WD; | |
351 | 355 | #endif |
352 | 356 | err = _fortuna_reseed(prng); |
353 | 357 | prng->ready = (err == CRYPT_OK) ? 1 : 0; |
377 | 381 | } |
378 | 382 | |
379 | 383 | /* do we have to reseed? */ |
380 | if (prng->fortuna.pool0_len >= 64) { | |
384 | if (prng->u.fortuna.pool0_len >= 64) { | |
381 | 385 | if (_fortuna_reseed(prng) != CRYPT_OK) { |
382 | 386 | goto LBL_UNLOCK; |
383 | 387 | } |
384 | 388 | } |
385 | 389 | |
386 | 390 | /* ensure that one reseed happened before allowing to read */ |
387 | if (prng->fortuna.reset_cnt == 0) { | |
391 | if (prng->u.fortuna.reset_cnt == 0) { | |
388 | 392 | goto LBL_UNLOCK; |
389 | 393 | } |
390 | 394 | |
394 | 398 | /* handle whole blocks without the extra XMEMCPY */ |
395 | 399 | while (outlen >= 16) { |
396 | 400 | /* encrypt the IV and store it */ |
397 | rijndael_ecb_encrypt(prng->fortuna.IV, out, &prng->fortuna.skey); | |
401 | rijndael_ecb_encrypt(prng->u.fortuna.IV, out, &prng->u.fortuna.skey); | |
398 | 402 | out += 16; |
399 | 403 | outlen -= 16; |
400 | 404 | _fortuna_update_iv(prng); |
402 | 406 | |
403 | 407 | /* left over bytes? */ |
404 | 408 | if (outlen > 0) { |
405 | rijndael_ecb_encrypt(prng->fortuna.IV, tmp, &prng->fortuna.skey); | |
409 | rijndael_ecb_encrypt(prng->u.fortuna.IV, tmp, &prng->u.fortuna.skey); | |
406 | 410 | XMEMCPY(out, tmp, outlen); |
407 | 411 | _fortuna_update_iv(prng); |
408 | 412 | } |
409 | 413 | |
410 | 414 | /* generate new key */ |
411 | rijndael_ecb_encrypt(prng->fortuna.IV, prng->fortuna.K , &prng->fortuna.skey); | |
415 | rijndael_ecb_encrypt(prng->u.fortuna.IV, prng->u.fortuna.K , &prng->u.fortuna.skey); | |
412 | 416 | _fortuna_update_iv(prng); |
413 | 417 | |
414 | rijndael_ecb_encrypt(prng->fortuna.IV, prng->fortuna.K+16, &prng->fortuna.skey); | |
418 | rijndael_ecb_encrypt(prng->u.fortuna.IV, prng->u.fortuna.K+16, &prng->u.fortuna.skey); | |
415 | 419 | _fortuna_update_iv(prng); |
416 | 420 | |
417 | if (rijndael_setup(prng->fortuna.K, 32, 0, &prng->fortuna.skey) != CRYPT_OK) { | |
421 | if (rijndael_setup(prng->u.fortuna.K, 32, 0, &prng->u.fortuna.skey) != CRYPT_OK) { | |
418 | 422 | tlen = 0; |
419 | 423 | } |
420 | 424 | |
443 | 447 | |
444 | 448 | /* terminate all the hashes */ |
445 | 449 | for (x = 0; x < LTC_FORTUNA_POOLS; x++) { |
446 | if ((err = sha256_done(&(prng->fortuna.pool[x]), tmp)) != CRYPT_OK) { | |
450 | if ((err = sha256_done(&(prng->u.fortuna.pool[x]), tmp)) != CRYPT_OK) { | |
447 | 451 | goto LBL_UNLOCK; |
448 | 452 | } |
449 | 453 | } |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file prngs/rc4.c |
38 | 38 | LTC_ARGCHK(prng != NULL); |
39 | 39 | prng->ready = 0; |
40 | 40 | /* set entropy (key) size to zero */ |
41 | prng->rc4.s.x = 0; | |
41 | prng->u.rc4.s.x = 0; | |
42 | 42 | /* clear entropy (key) buffer */ |
43 | XMEMSET(&prng->rc4.s.buf, 0, sizeof(prng->rc4.s.buf)); | |
43 | XMEMSET(&prng->u.rc4.s.buf, 0, sizeof(prng->u.rc4.s.buf)); | |
44 | 44 | LTC_MUTEX_INIT(&prng->lock) |
45 | 45 | return CRYPT_OK; |
46 | 46 | } |
65 | 65 | LTC_MUTEX_LOCK(&prng->lock); |
66 | 66 | if (prng->ready) { |
67 | 67 | /* rc4_ready() was already called, do "rekey" operation */ |
68 | if ((err = rc4_stream_keystream(&prng->rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; | |
68 | if ((err = rc4_stream_keystream(&prng->u.rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; | |
69 | 69 | for(i = 0; i < inlen; i++) buf[i % sizeof(buf)] ^= in[i]; |
70 | 70 | /* initialize RC4 */ |
71 | if ((err = rc4_stream_setup(&prng->rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; | |
71 | if ((err = rc4_stream_setup(&prng->u.rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; | |
72 | 72 | /* drop first 3072 bytes - https://en.wikipedia.org/wiki/RC4#Fluhrer.2C_Mantin_and_Shamir_attack */ |
73 | for (i = 0; i < 12; i++) rc4_stream_keystream(&prng->rc4.s, buf, sizeof(buf)); | |
73 | for (i = 0; i < 12; i++) rc4_stream_keystream(&prng->u.rc4.s, buf, sizeof(buf)); | |
74 | 74 | zeromem(buf, sizeof(buf)); |
75 | 75 | } |
76 | 76 | else { |
77 | 77 | /* rc4_ready() was not called yet, add entropy to the buffer */ |
78 | while (inlen--) prng->rc4.s.buf[prng->rc4.s.x++ % sizeof(prng->rc4.s.buf)] ^= *in++; | |
78 | while (inlen--) prng->u.rc4.s.buf[prng->u.rc4.s.x++ % sizeof(prng->u.rc4.s.buf)] ^= *in++; | |
79 | 79 | } |
80 | 80 | err = CRYPT_OK; |
81 | 81 | LBL_UNLOCK: |
98 | 98 | |
99 | 99 | LTC_MUTEX_LOCK(&prng->lock); |
100 | 100 | if (prng->ready) { err = CRYPT_OK; goto LBL_UNLOCK; } |
101 | XMEMCPY(buf, prng->rc4.s.buf, sizeof(buf)); | |
101 | XMEMCPY(buf, prng->u.rc4.s.buf, sizeof(buf)); | |
102 | 102 | /* initialize RC4 */ |
103 | len = MIN(prng->rc4.s.x, 256); /* TODO: we can perhaps always use all 256 bytes */ | |
104 | if ((err = rc4_stream_setup(&prng->rc4.s, buf, len)) != CRYPT_OK) goto LBL_UNLOCK; | |
103 | len = MIN(prng->u.rc4.s.x, 256); /* TODO: we can perhaps always use all 256 bytes */ | |
104 | if ((err = rc4_stream_setup(&prng->u.rc4.s, buf, len)) != CRYPT_OK) goto LBL_UNLOCK; | |
105 | 105 | /* drop first 3072 bytes - https://en.wikipedia.org/wiki/RC4#Fluhrer.2C_Mantin_and_Shamir_attack */ |
106 | for (i = 0; i < 12; i++) rc4_stream_keystream(&prng->rc4.s, buf, sizeof(buf)); | |
106 | for (i = 0; i < 12; i++) rc4_stream_keystream(&prng->u.rc4.s, buf, sizeof(buf)); | |
107 | 107 | prng->ready = 1; |
108 | 108 | LBL_UNLOCK: |
109 | 109 | LTC_MUTEX_UNLOCK(&prng->lock); |
122 | 122 | if (outlen == 0 || prng == NULL || out == NULL) return 0; |
123 | 123 | LTC_MUTEX_LOCK(&prng->lock); |
124 | 124 | if (!prng->ready) { outlen = 0; goto LBL_UNLOCK; } |
125 | if (rc4_stream_keystream(&prng->rc4.s, out, outlen) != CRYPT_OK) outlen = 0; | |
125 | if (rc4_stream_keystream(&prng->u.rc4.s, out, outlen) != CRYPT_OK) outlen = 0; | |
126 | 126 | LBL_UNLOCK: |
127 | 127 | LTC_MUTEX_UNLOCK(&prng->lock); |
128 | 128 | return outlen; |
139 | 139 | LTC_ARGCHK(prng != NULL); |
140 | 140 | LTC_MUTEX_LOCK(&prng->lock); |
141 | 141 | prng->ready = 0; |
142 | err = rc4_stream_done(&prng->rc4.s); | |
142 | err = rc4_stream_done(&prng->u.rc4.s); | |
143 | 143 | LTC_MUTEX_UNLOCK(&prng->lock); |
144 | 144 | LTC_MUTEX_DESTROY(&prng->lock); |
145 | 145 | return err; |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_RNG_GET_BYTES |
11 | 11 | /** |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | #ifdef LTC_RNG_MAKE_PRNG |
11 | 11 | /** |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | /** |
12 | 12 | @file prngs/sober128.c |
39 | 39 | { |
40 | 40 | LTC_ARGCHK(prng != NULL); |
41 | 41 | prng->ready = 0; |
42 | XMEMSET(&prng->sober128.ent, 0, sizeof(prng->sober128.ent)); | |
43 | prng->sober128.idx = 0; | |
42 | XMEMSET(&prng->u.sober128.ent, 0, sizeof(prng->u.sober128.ent)); | |
43 | prng->u.sober128.idx = 0; | |
44 | 44 | LTC_MUTEX_INIT(&prng->lock) |
45 | 45 | return CRYPT_OK; |
46 | 46 | } |
65 | 65 | LTC_MUTEX_LOCK(&prng->lock); |
66 | 66 | if (prng->ready) { |
67 | 67 | /* sober128_ready() was already called, do "rekey" operation */ |
68 | if ((err = sober128_stream_keystream(&prng->sober128.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; | |
68 | if ((err = sober128_stream_keystream(&prng->u.sober128.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK; | |
69 | 69 | for(i = 0; i < inlen; i++) buf[i % sizeof(buf)] ^= in[i]; |
70 | 70 | /* key 32 bytes, 20 rounds */ |
71 | if ((err = sober128_stream_setup(&prng->sober128.s, buf, 32)) != CRYPT_OK) goto LBL_UNLOCK; | |
71 | if ((err = sober128_stream_setup(&prng->u.sober128.s, buf, 32)) != CRYPT_OK) goto LBL_UNLOCK; | |
72 | 72 | /* iv 8 bytes */ |
73 | if ((err = sober128_stream_setiv(&prng->sober128.s, buf + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK; | |
73 | if ((err = sober128_stream_setiv(&prng->u.sober128.s, buf + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK; | |
74 | 74 | /* clear KEY + IV */ |
75 | 75 | zeromem(buf, sizeof(buf)); |
76 | 76 | } |
77 | 77 | else { |
78 | 78 | /* sober128_ready() was not called yet, add entropy to ent buffer */ |
79 | while (inlen--) prng->sober128.ent[prng->sober128.idx++ % sizeof(prng->sober128.ent)] ^= *in++; | |
79 | while (inlen--) prng->u.sober128.ent[prng->u.sober128.idx++ % sizeof(prng->u.sober128.ent)] ^= *in++; | |
80 | 80 | } |
81 | 81 | err = CRYPT_OK; |
82 | 82 | LBL_UNLOCK: |
98 | 98 | LTC_MUTEX_LOCK(&prng->lock); |
99 | 99 | if (prng->ready) { err = CRYPT_OK; goto LBL_UNLOCK; } |
100 | 100 | /* key 32 bytes, 20 rounds */ |
101 | if ((err = sober128_stream_setup(&prng->sober128.s, prng->sober128.ent, 32)) != CRYPT_OK) goto LBL_UNLOCK; | |
101 | if ((err = sober128_stream_setup(&prng->u.sober128.s, prng->u.sober128.ent, 32)) != CRYPT_OK) goto LBL_UNLOCK; | |
102 | 102 | /* iv 8 bytes */ |
103 | if ((err = sober128_stream_setiv(&prng->sober128.s, prng->sober128.ent + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK; | |
104 | XMEMSET(&prng->sober128.ent, 0, sizeof(prng->sober128.ent)); | |
105 | prng->sober128.idx = 0; | |
103 | if ((err = sober128_stream_setiv(&prng->u.sober128.s, prng->u.sober128.ent + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK; | |
104 | XMEMSET(&prng->u.sober128.ent, 0, sizeof(prng->u.sober128.ent)); | |
105 | prng->u.sober128.idx = 0; | |
106 | 106 | prng->ready = 1; |
107 | 107 | LBL_UNLOCK: |
108 | 108 | LTC_MUTEX_UNLOCK(&prng->lock); |
121 | 121 | if (outlen == 0 || prng == NULL || out == NULL) return 0; |
122 | 122 | LTC_MUTEX_LOCK(&prng->lock); |
123 | 123 | if (!prng->ready) { outlen = 0; goto LBL_UNLOCK; } |
124 | if (sober128_stream_keystream(&prng->sober128.s, out, outlen) != CRYPT_OK) outlen = 0; | |
124 | if (sober128_stream_keystream(&prng->u.sober128.s, out, outlen) != CRYPT_OK) outlen = 0; | |
125 | 125 | LBL_UNLOCK: |
126 | 126 | LTC_MUTEX_UNLOCK(&prng->lock); |
127 | 127 | return outlen; |
138 | 138 | LTC_ARGCHK(prng != NULL); |
139 | 139 | LTC_MUTEX_LOCK(&prng->lock); |
140 | 140 | prng->ready = 0; |
141 | err = sober128_stream_done(&prng->sober128.s); | |
141 | err = sober128_stream_done(&prng->u.sober128.s); | |
142 | 142 | LTC_MUTEX_UNLOCK(&prng->lock); |
143 | 143 | LTC_MUTEX_DESTROY(&prng->lock); |
144 | 144 | return err; |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file sprng.c |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file yarrow.c |
42 | 42 | /* these are the default hash/cipher combo used */ |
43 | 43 | #ifdef LTC_RIJNDAEL |
44 | 44 | #if LTC_YARROW_AES==0 |
45 | prng->yarrow.cipher = register_cipher(&rijndael_enc_desc); | |
45 | prng->u.yarrow.cipher = register_cipher(&rijndael_enc_desc); | |
46 | 46 | #elif LTC_YARROW_AES==1 |
47 | prng->yarrow.cipher = register_cipher(&aes_enc_desc); | |
47 | prng->u.yarrow.cipher = register_cipher(&aes_enc_desc); | |
48 | 48 | #elif LTC_YARROW_AES==2 |
49 | prng->yarrow.cipher = register_cipher(&rijndael_desc); | |
49 | prng->u.yarrow.cipher = register_cipher(&rijndael_desc); | |
50 | 50 | #elif LTC_YARROW_AES==3 |
51 | prng->yarrow.cipher = register_cipher(&aes_desc); | |
51 | prng->u.yarrow.cipher = register_cipher(&aes_desc); | |
52 | 52 | #endif |
53 | 53 | #elif defined(LTC_BLOWFISH) |
54 | prng->yarrow.cipher = register_cipher(&blowfish_desc); | |
54 | prng->u.yarrow.cipher = register_cipher(&blowfish_desc); | |
55 | 55 | #elif defined(LTC_TWOFISH) |
56 | prng->yarrow.cipher = register_cipher(&twofish_desc); | |
56 | prng->u.yarrow.cipher = register_cipher(&twofish_desc); | |
57 | 57 | #elif defined(LTC_RC6) |
58 | prng->yarrow.cipher = register_cipher(&rc6_desc); | |
58 | prng->u.yarrow.cipher = register_cipher(&rc6_desc); | |
59 | 59 | #elif defined(LTC_RC5) |
60 | prng->yarrow.cipher = register_cipher(&rc5_desc); | |
60 | prng->u.yarrow.cipher = register_cipher(&rc5_desc); | |
61 | 61 | #elif defined(LTC_SAFERP) |
62 | prng->yarrow.cipher = register_cipher(&saferp_desc); | |
62 | prng->u.yarrow.cipher = register_cipher(&saferp_desc); | |
63 | 63 | #elif defined(LTC_RC2) |
64 | prng->yarrow.cipher = register_cipher(&rc2_desc); | |
64 | prng->u.yarrow.cipher = register_cipher(&rc2_desc); | |
65 | 65 | #elif defined(LTC_NOEKEON) |
66 | prng->yarrow.cipher = register_cipher(&noekeon_desc); | |
66 | prng->u.yarrow.cipher = register_cipher(&noekeon_desc); | |
67 | 67 | #elif defined(LTC_ANUBIS) |
68 | prng->yarrow.cipher = register_cipher(&anubis_desc); | |
68 | prng->u.yarrow.cipher = register_cipher(&anubis_desc); | |
69 | 69 | #elif defined(LTC_KSEED) |
70 | prng->yarrow.cipher = register_cipher(&kseed_desc); | |
70 | prng->u.yarrow.cipher = register_cipher(&kseed_desc); | |
71 | 71 | #elif defined(LTC_KHAZAD) |
72 | prng->yarrow.cipher = register_cipher(&khazad_desc); | |
72 | prng->u.yarrow.cipher = register_cipher(&khazad_desc); | |
73 | 73 | #elif defined(LTC_CAST5) |
74 | prng->yarrow.cipher = register_cipher(&cast5_desc); | |
74 | prng->u.yarrow.cipher = register_cipher(&cast5_desc); | |
75 | 75 | #elif defined(LTC_XTEA) |
76 | prng->yarrow.cipher = register_cipher(&xtea_desc); | |
76 | prng->u.yarrow.cipher = register_cipher(&xtea_desc); | |
77 | 77 | #elif defined(LTC_SAFER) |
78 | prng->yarrow.cipher = register_cipher(&safer_sk128_desc); | |
78 | prng->u.yarrow.cipher = register_cipher(&safer_sk128_desc); | |
79 | 79 | #elif defined(LTC_DES) |
80 | prng->yarrow.cipher = register_cipher(&des3_desc); | |
80 | prng->u.yarrow.cipher = register_cipher(&des3_desc); | |
81 | 81 | #else |
82 | 82 | #error LTC_YARROW needs at least one CIPHER |
83 | 83 | #endif |
84 | if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) { | |
84 | if ((err = cipher_is_valid(prng->u.yarrow.cipher)) != CRYPT_OK) { | |
85 | 85 | return err; |
86 | 86 | } |
87 | 87 | |
88 | 88 | #ifdef LTC_SHA256 |
89 | prng->yarrow.hash = register_hash(&sha256_desc); | |
89 | prng->u.yarrow.hash = register_hash(&sha256_desc); | |
90 | 90 | #elif defined(LTC_SHA512) |
91 | prng->yarrow.hash = register_hash(&sha512_desc); | |
91 | prng->u.yarrow.hash = register_hash(&sha512_desc); | |
92 | 92 | #elif defined(LTC_TIGER) |
93 | prng->yarrow.hash = register_hash(&tiger_desc); | |
93 | prng->u.yarrow.hash = register_hash(&tiger_desc); | |
94 | 94 | #elif defined(LTC_SHA1) |
95 | prng->yarrow.hash = register_hash(&sha1_desc); | |
95 | prng->u.yarrow.hash = register_hash(&sha1_desc); | |
96 | 96 | #elif defined(LTC_RIPEMD320) |
97 | prng->yarrow.hash = register_hash(&rmd320_desc); | |
97 | prng->u.yarrow.hash = register_hash(&rmd320_desc); | |
98 | 98 | #elif defined(LTC_RIPEMD256) |
99 | prng->yarrow.hash = register_hash(&rmd256_desc); | |
99 | prng->u.yarrow.hash = register_hash(&rmd256_desc); | |
100 | 100 | #elif defined(LTC_RIPEMD160) |
101 | prng->yarrow.hash = register_hash(&rmd160_desc); | |
101 | prng->u.yarrow.hash = register_hash(&rmd160_desc); | |
102 | 102 | #elif defined(LTC_RIPEMD128) |
103 | prng->yarrow.hash = register_hash(&rmd128_desc); | |
103 | prng->u.yarrow.hash = register_hash(&rmd128_desc); | |
104 | 104 | #elif defined(LTC_MD5) |
105 | prng->yarrow.hash = register_hash(&md5_desc); | |
105 | prng->u.yarrow.hash = register_hash(&md5_desc); | |
106 | 106 | #elif defined(LTC_MD4) |
107 | prng->yarrow.hash = register_hash(&md4_desc); | |
107 | prng->u.yarrow.hash = register_hash(&md4_desc); | |
108 | 108 | #elif defined(LTC_MD2) |
109 | prng->yarrow.hash = register_hash(&md2_desc); | |
109 | prng->u.yarrow.hash = register_hash(&md2_desc); | |
110 | 110 | #elif defined(LTC_WHIRLPOOL) |
111 | prng->yarrow.hash = register_hash(&whirlpool_desc); | |
111 | prng->u.yarrow.hash = register_hash(&whirlpool_desc); | |
112 | 112 | #else |
113 | 113 | #error LTC_YARROW needs at least one HASH |
114 | 114 | #endif |
115 | if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) { | |
115 | if ((err = hash_is_valid(prng->u.yarrow.hash)) != CRYPT_OK) { | |
116 | 116 | return err; |
117 | 117 | } |
118 | 118 | |
119 | 119 | /* zero the memory used */ |
120 | zeromem(prng->yarrow.pool, sizeof(prng->yarrow.pool)); | |
120 | zeromem(prng->u.yarrow.pool, sizeof(prng->u.yarrow.pool)); | |
121 | 121 | LTC_MUTEX_INIT(&prng->lock) |
122 | 122 | |
123 | 123 | return CRYPT_OK; |
141 | 141 | |
142 | 142 | LTC_MUTEX_LOCK(&prng->lock); |
143 | 143 | |
144 | if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) { | |
144 | if ((err = hash_is_valid(prng->u.yarrow.hash)) != CRYPT_OK) { | |
145 | 145 | goto LBL_UNLOCK; |
146 | 146 | } |
147 | 147 | |
148 | 148 | /* start the hash */ |
149 | if ((err = hash_descriptor[prng->yarrow.hash].init(&md)) != CRYPT_OK) { | |
149 | if ((err = hash_descriptor[prng->u.yarrow.hash].init(&md)) != CRYPT_OK) { | |
150 | 150 | goto LBL_UNLOCK; |
151 | 151 | } |
152 | 152 | |
153 | 153 | /* hash the current pool */ |
154 | if ((err = hash_descriptor[prng->yarrow.hash].process(&md, prng->yarrow.pool, | |
155 | hash_descriptor[prng->yarrow.hash].hashsize)) != CRYPT_OK) { | |
154 | if ((err = hash_descriptor[prng->u.yarrow.hash].process(&md, prng->u.yarrow.pool, | |
155 | hash_descriptor[prng->u.yarrow.hash].hashsize)) != CRYPT_OK) { | |
156 | 156 | goto LBL_UNLOCK; |
157 | 157 | } |
158 | 158 | |
159 | 159 | /* add the new entropy */ |
160 | if ((err = hash_descriptor[prng->yarrow.hash].process(&md, in, inlen)) != CRYPT_OK) { | |
160 | if ((err = hash_descriptor[prng->u.yarrow.hash].process(&md, in, inlen)) != CRYPT_OK) { | |
161 | 161 | goto LBL_UNLOCK; |
162 | 162 | } |
163 | 163 | |
164 | 164 | /* store result */ |
165 | err = hash_descriptor[prng->yarrow.hash].done(&md, prng->yarrow.pool); | |
165 | err = hash_descriptor[prng->u.yarrow.hash].done(&md, prng->u.yarrow.pool); | |
166 | 166 | |
167 | 167 | LBL_UNLOCK: |
168 | 168 | LTC_MUTEX_UNLOCK(&prng->lock); |
182 | 182 | |
183 | 183 | LTC_MUTEX_LOCK(&prng->lock); |
184 | 184 | |
185 | if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) { | |
186 | goto LBL_UNLOCK; | |
187 | } | |
188 | ||
189 | if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) { | |
185 | if ((err = hash_is_valid(prng->u.yarrow.hash)) != CRYPT_OK) { | |
186 | goto LBL_UNLOCK; | |
187 | } | |
188 | ||
189 | if ((err = cipher_is_valid(prng->u.yarrow.cipher)) != CRYPT_OK) { | |
190 | 190 | goto LBL_UNLOCK; |
191 | 191 | } |
192 | 192 | |
193 | 193 | /* setup CTR mode using the "pool" as the key */ |
194 | ks = (int)hash_descriptor[prng->yarrow.hash].hashsize; | |
195 | if ((err = cipher_descriptor[prng->yarrow.cipher].keysize(&ks)) != CRYPT_OK) { | |
196 | goto LBL_UNLOCK; | |
197 | } | |
198 | ||
199 | if ((err = ctr_start(prng->yarrow.cipher, /* what cipher to use */ | |
200 | prng->yarrow.pool, /* IV */ | |
201 | prng->yarrow.pool, ks, /* KEY and key size */ | |
194 | ks = (int)hash_descriptor[prng->u.yarrow.hash].hashsize; | |
195 | if ((err = cipher_descriptor[prng->u.yarrow.cipher].keysize(&ks)) != CRYPT_OK) { | |
196 | goto LBL_UNLOCK; | |
197 | } | |
198 | ||
199 | if ((err = ctr_start(prng->u.yarrow.cipher, /* what cipher to use */ | |
200 | prng->u.yarrow.pool, /* IV */ | |
201 | prng->u.yarrow.pool, ks, /* KEY and key size */ | |
202 | 202 | 0, /* number of rounds */ |
203 | 203 | CTR_COUNTER_LITTLE_ENDIAN, /* little endian counter */ |
204 | &prng->yarrow.ctr)) != CRYPT_OK) { | |
204 | &prng->u.yarrow.ctr)) != CRYPT_OK) { | |
205 | 205 | goto LBL_UNLOCK; |
206 | 206 | } |
207 | 207 | prng->ready = 1; |
233 | 233 | zeromem(out, outlen); |
234 | 234 | |
235 | 235 | /* now randomize it */ |
236 | if (ctr_encrypt(out, out, outlen, &prng->yarrow.ctr) != CRYPT_OK) { | |
236 | if (ctr_encrypt(out, out, outlen, &prng->u.yarrow.ctr) != CRYPT_OK) { | |
237 | 237 | outlen = 0; |
238 | 238 | } |
239 | 239 | |
258 | 258 | /* call cipher done when we invent one ;-) */ |
259 | 259 | |
260 | 260 | /* we invented one */ |
261 | err = ctr_done(&prng->yarrow.ctr); | |
261 | err = ctr_done(&prng->u.yarrow.ctr); | |
262 | 262 | |
263 | 263 | LTC_MUTEX_UNLOCK(&prng->lock); |
264 | 264 | LTC_MUTEX_DESTROY(&prng->lock); |
311 | 311 | } |
312 | 312 | |
313 | 313 | /* now let's test the hash/cipher that was chosen */ |
314 | if (cipher_descriptor[prng.yarrow.cipher].test && | |
315 | ((err = cipher_descriptor[prng.yarrow.cipher].test()) != CRYPT_OK)) { | |
316 | return err; | |
317 | } | |
318 | if (hash_descriptor[prng.yarrow.hash].test && | |
319 | ((err = hash_descriptor[prng.yarrow.hash].test()) != CRYPT_OK)) { | |
314 | if (cipher_descriptor[prng.u.yarrow.cipher].test && | |
315 | ((err = cipher_descriptor[prng.u.yarrow.cipher].test()) != CRYPT_OK)) { | |
316 | return err; | |
317 | } | |
318 | if (hash_descriptor[prng.u.yarrow.hash].test && | |
319 | ((err = hash_descriptor[prng.u.yarrow.hash].test()) != CRYPT_OK)) { | |
320 | 320 | return err; |
321 | 321 | } |
322 | 322 |
11 | 11 | * Public domain from D. J. Bernstein |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_CHACHA |
17 | 17 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_CHACHA |
12 | 12 |
11 | 11 | * Public domain from D. J. Bernstein |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_CHACHA |
17 | 17 |
11 | 11 | * Public domain from D. J. Bernstein |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_CHACHA |
17 | 17 |
11 | 11 | * Public domain from D. J. Bernstein |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_CHACHA |
17 | 17 |
11 | 11 | * Public domain from D. J. Bernstein |
12 | 12 | */ |
13 | 13 | |
14 | #include "tomcrypt.h" | |
14 | #include "tomcrypt_private.h" | |
15 | 15 | |
16 | 16 | #ifdef LTC_CHACHA |
17 | 17 |
61 | 61 | ******************************************************************************/ |
62 | 62 | |
63 | 63 | |
64 | #include "tomcrypt.h" | |
64 | #include "tomcrypt_private.h" | |
65 | 65 | |
66 | 66 | #ifdef LTC_RABBIT |
67 | 67 |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_RC4_STREAM |
12 | 12 |
12 | 12 | * Public domain from D. J. Bernstein |
13 | 13 | */ |
14 | 14 | |
15 | #include "tomcrypt.h" | |
15 | #include "tomcrypt_private.h" | |
16 | 16 | |
17 | 17 | #ifdef LTC_SALSA20 |
18 | 18 | |
61 | 61 | LTC_ARGCHK(st != NULL); |
62 | 62 | LTC_ARGCHK(in != NULL); |
63 | 63 | LTC_ARGCHK(out != NULL); |
64 | LTC_ARGCHK(st->ivlen == 8); | |
64 | LTC_ARGCHK(st->ivlen == 8 || st->ivlen == 24); | |
65 | 65 | |
66 | 66 | if (st->ksleft > 0) { |
67 | 67 | j = MIN(st->ksleft, inlen); |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | 8 | |
9 | #include "tomcrypt.h" | |
9 | #include "tomcrypt_private.h" | |
10 | 10 | |
11 | 11 | #ifdef LTC_SALSA20 |
12 | 12 |
12 | 12 | * Public domain from D. J. Bernstein |
13 | 13 | */ |
14 | 14 | |
15 | #include "tomcrypt.h" | |
15 | #include "tomcrypt_private.h" | |
16 | 16 | |
17 | 17 | #ifdef LTC_SALSA20 |
18 | 18 |
12 | 12 | * Public domain from D. J. Bernstein |
13 | 13 | */ |
14 | 14 | |
15 | #include "tomcrypt.h" | |
15 | #include "tomcrypt_private.h" | |
16 | 16 | |
17 | 17 | #ifdef LTC_SALSA20 |
18 | 18 |
12 | 12 | * Public domain from D. J. Bernstein |
13 | 13 | */ |
14 | 14 | |
15 | #include "tomcrypt.h" | |
15 | #include "tomcrypt_private.h" | |
16 | 16 | |
17 | 17 | #ifdef LTC_SALSA20 |
18 | 18 |
0 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
1 | * | |
2 | * LibTomCrypt is a library that provides various cryptographic | |
3 | * algorithms in a highly modular and flexible manner. | |
4 | * | |
5 | * The library is free for all purposes without any express | |
6 | * guarantee it works. | |
7 | */ | |
8 | ||
9 | /* The implementation is based on: | |
10 | * "Extending the Salsa20 nonce", https://cr.yp.to/snuffle/xsalsa-20081128.pdf | |
11 | * "Salsa20 specification", http://cr.yp.to/snuffle/spec.pdf | |
12 | * and salsa20-ref.c version 20051118 | |
13 | * Public domain from D. J. Bernstein | |
14 | */ | |
15 | ||
16 | #include "tomcrypt.h" | |
17 | ||
18 | #ifdef LTC_XSALSA20 | |
19 | ||
20 | static const char * const constants = "expand 32-byte k"; | |
21 | ||
22 | #define QUARTERROUND(a,b,c,d) \ | |
23 | x[b] ^= (ROL((x[a] + x[d]), 7)); \ | |
24 | x[c] ^= (ROL((x[b] + x[a]), 9)); \ | |
25 | x[d] ^= (ROL((x[c] + x[b]), 13)); \ | |
26 | x[a] ^= (ROL((x[d] + x[c]), 18)); | |
27 | ||
28 | /* use modified salsa20 doubleround (no final addition as in salsa20) */ | |
29 | static void _xsalsa20_doubleround(ulong32 *x, int rounds) | |
30 | { | |
31 | int i; | |
32 | ||
33 | for (i = rounds; i > 0; i -= 2) { | |
34 | /* columnround */ | |
35 | QUARTERROUND( 0, 4, 8,12) | |
36 | QUARTERROUND( 5, 9,13, 1) | |
37 | QUARTERROUND(10,14, 2, 6) | |
38 | QUARTERROUND(15, 3, 7,11) | |
39 | /* rowround */ | |
40 | QUARTERROUND( 0, 1, 2, 3) | |
41 | QUARTERROUND( 5, 6, 7, 4) | |
42 | QUARTERROUND(10,11, 8, 9) | |
43 | QUARTERROUND(15,12,13,14) | |
44 | } | |
45 | } | |
46 | ||
47 | #undef QUARTERROUND | |
48 | ||
49 | /** | |
50 | Initialize an XSalsa20 context | |
51 | @param st [out] The destination of the XSalsa20 state | |
52 | @param key The secret key | |
53 | @param keylen The length of the secret key, must be 32 (octets) | |
54 | @param nonce The nonce | |
55 | @param noncelen The length of the nonce, must be 24 (octets) | |
56 | @param rounds Number of rounds (must be evenly divisible by 2, default is 20) | |
57 | @return CRYPT_OK if successful | |
58 | */ | |
59 | int xsalsa20_setup(salsa20_state *st, const unsigned char *key, unsigned long keylen, | |
60 | const unsigned char *nonce, unsigned long noncelen, | |
61 | int rounds) | |
62 | { | |
63 | const int sti[] = {0, 5, 10, 15, 6, 7, 8, 9}; /* indices used to build subkey fm x */ | |
64 | ulong32 x[64]; /* input to & output fm doubleround */ | |
65 | unsigned char subkey[32]; | |
66 | int i; | |
67 | ||
68 | LTC_ARGCHK(st != NULL); | |
69 | LTC_ARGCHK(key != NULL); | |
70 | LTC_ARGCHK(keylen == 32); | |
71 | LTC_ARGCHK(nonce != NULL); | |
72 | LTC_ARGCHK(noncelen == 24); | |
73 | if (rounds == 0) rounds = 20; | |
74 | LTC_ARGCHK(rounds % 2 == 0); /* number of rounds must be evenly divisible by 2 */ | |
75 | ||
76 | /* load the state to "hash" the key */ | |
77 | LOAD32L(x[ 0], constants + 0); | |
78 | LOAD32L(x[ 5], constants + 4); | |
79 | LOAD32L(x[10], constants + 8); | |
80 | LOAD32L(x[15], constants + 12); | |
81 | LOAD32L(x[ 1], key + 0); | |
82 | LOAD32L(x[ 2], key + 4); | |
83 | LOAD32L(x[ 3], key + 8); | |
84 | LOAD32L(x[ 4], key + 12); | |
85 | LOAD32L(x[11], key + 16); | |
86 | LOAD32L(x[12], key + 20); | |
87 | LOAD32L(x[13], key + 24); | |
88 | LOAD32L(x[14], key + 28); | |
89 | LOAD32L(x[ 6], nonce + 0); | |
90 | LOAD32L(x[ 7], nonce + 4); | |
91 | LOAD32L(x[ 8], nonce + 8); | |
92 | LOAD32L(x[ 9], nonce + 12); | |
93 | ||
94 | /* use modified salsa20 doubleround (no final addition) */ | |
95 | _xsalsa20_doubleround(x, rounds); | |
96 | ||
97 | /* extract the subkey */ | |
98 | for (i = 0; i < 8; ++i) { | |
99 | STORE32L(x[sti[i]], subkey + 4 * i); | |
100 | } | |
101 | ||
102 | /* load the final initial state */ | |
103 | LOAD32L(st->input[ 0], constants + 0); | |
104 | LOAD32L(st->input[ 5], constants + 4); | |
105 | LOAD32L(st->input[10], constants + 8); | |
106 | LOAD32L(st->input[15], constants + 12); | |
107 | LOAD32L(st->input[ 1], subkey + 0); | |
108 | LOAD32L(st->input[ 2], subkey + 4); | |
109 | LOAD32L(st->input[ 3], subkey + 8); | |
110 | LOAD32L(st->input[ 4], subkey + 12); | |
111 | LOAD32L(st->input[11], subkey + 16); | |
112 | LOAD32L(st->input[12], subkey + 20); | |
113 | LOAD32L(st->input[13], subkey + 24); | |
114 | LOAD32L(st->input[14], subkey + 28); | |
115 | LOAD32L(st->input[ 6], &(nonce[16]) + 0); | |
116 | LOAD32L(st->input[ 7], &(nonce[16]) + 4); | |
117 | st->input[ 8] = 0; | |
118 | st->input[ 9] = 0; | |
119 | st->rounds = rounds; | |
120 | st->ksleft = 0; | |
121 | st->ivlen = 24; /* set switch to say nonce/IV has been loaded */ | |
122 | ||
123 | #ifdef LTC_CLEAN_STACK | |
124 | zeromem(x, sizeof(x)); | |
125 | zeromem(subkey, sizeof(subkey)); | |
126 | #endif | |
127 | ||
128 | return CRYPT_OK; | |
129 | } | |
130 | ||
131 | ||
132 | #endif | |
133 | ||
134 | /* ref: $Format:%D$ */ | |
135 | /* git commit: $Format:%H$ */ | |
136 | /* commit time: $Format:%ai$ */ |
5 | 5 | * The library is free for all purposes without any express |
6 | 6 | * guarantee it works. |
7 | 7 | */ |
8 | #include "tomcrypt.h" | |
8 | #include "tomcrypt_private.h" | |
9 | 9 | |
10 | 10 | /** |
11 | 11 | @file sober128_stream.c |
29 | 29 | * <thomas.pornin@cryptolog.com> |
30 | 30 | */ |
31 | 31 | |
32 | #include "tomcrypt.h" | |
32 | #include "tomcrypt_private.h" | |
33 | 33 | |
34 | 34 | #ifdef LTC_SOSEMANUK |
35 | 35 | |
256 | 256 | |
257 | 257 | LTC_ARGCHK(ss != NULL); |
258 | 258 | LTC_ARGCHK(key != NULL); |
259 | LTC_ARGCHK(keylen > 0 && keylen <= 32); | |
259 | 260 | |
260 | 261 | /* |
261 | 262 | * The key is copied into the wbuf[] buffer and padded to 256 bits |
262 | 263 | * as described in the Serpent specification. |
263 | 264 | */ |
264 | if (keylen == 0 || keylen > 32) { | |
265 | fprintf(stderr, "invalid key size: %lu\n", | |
266 | (unsigned long)keylen); | |
267 | exit(EXIT_FAILURE); | |
268 | } | |
269 | 265 | XMEMCPY(wbuf, key, keylen); |
270 | 266 | if (keylen < 32) { |
271 | 267 | wbuf[keylen] = 0x01; |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_ERROR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | static const struct { |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_FAST_MP_INVMOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* computes the modular inverse via binary extended euclidean algorithm, |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* computes xR**-1 == x (mod N) via Montgomery Reduction |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_FAST_S_MP_MUL_DIGS_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* Fast (comba) multiplier |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* this is a modified version of fast_s_mul_digs that only produces |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_FAST_S_MP_SQR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* the jist of squaring... |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_2EXPT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* computes a = 2**b |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_ABS_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* b = |a| |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_ADD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* high level addition (handles signs) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_ADD_D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* single digit addition */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_ADDMOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* d = a + b (mod c) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_AND_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* AND two ints together */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_CLAMP_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* trim unused digits |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_CLEAR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* clear one (frees) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_CLEAR_MULTI_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
14 | ||
16 | 15 | #include <stdarg.h> |
17 | 16 | |
18 | 17 | void mp_clear_multi(mp_int *mp, ...) |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_CMP_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* compare two ints (signed)*/ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_CMP_D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* compare a digit */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_CMP_MAG_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* compare maginitude of two ints (unsigned) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_CNT_LSB_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | static const int lnz[16] = { |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_COPY_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* copy, b = a */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_COUNT_BITS_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* returns the number of bits in an int */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_DIV_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | #ifdef BN_MP_DIV_SMALL |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_DIV_2_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* b = a/2 */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_DIV_2D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* shift right by a certain bit count (store quotient in c, optional remainder in d) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_DIV_3_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* divide by three (based on routine from MPI and the GMP manual) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_DIV_D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | static int s_is_power_of_two(mp_digit b, int *p) |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_DR_IS_MODULUS_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* determines if a number is a valid DR modulus */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_DR_REDUCE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* reduce "x" in place modulo "n" using the Diminished Radix algorithm. |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_DR_SETUP_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* determines the setup value */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_EXCH_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* swap the elements of two integers, for cases where you can't simply swap the |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_EXPORT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* based on gmp's mpz_export. |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_EXPT_D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* wrapper function for mp_expt_d_ex() */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_EXPT_D_EX_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* calculate c = a**b using a square-multiply algorithm */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_EXPTMOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_EXPTMOD_FAST_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85 |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_EXTEUCLID_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* Extended euclidean algorithm of (a, b) produces |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_FREAD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | #ifndef LTM_NO_FILE |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_FWRITE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | #ifndef LTM_NO_FILE |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_GCD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* Greatest Common Divisor using the binary method */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_GET_INT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* get the lower 32-bits of an mp_int */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_GET_LONG_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* get the lower unsigned long of an mp_int, platform dependent */ |
0 | #include <tommath_private.h> | |
1 | #ifdef BN_MP_GET_LONG_LONG_C | |
2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis | |
3 | * | |
4 | * LibTomMath is a library that provides multiple-precision | |
5 | * integer arithmetic as well as number theoretic functionality. | |
6 | * | |
7 | * The library was designed directly after the MPI library by | |
8 | * Michael Fromberger but has been written from scratch with | |
9 | * additional optimizations in place. | |
10 | * | |
11 | * The library is free for all purposes without any express | |
12 | * guarantee it works. | |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | */ | |
16 | ||
17 | /* get the lower unsigned long long of an mp_int, platform dependent */ | |
18 | uint64_t mp_get_long_long(const mp_int *a) | |
19 | { | |
20 | int i; | |
21 | uint64_t res; | |
22 | ||
23 | if (a->used == 0) { | |
24 | return 0; | |
25 | } | |
26 | ||
27 | /* get number of digits of the lsb we have to read */ | |
28 | i = MIN(a->used, ((((int)sizeof(uint64_t) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; | |
29 | ||
30 | /* get most significant digit of result */ | |
31 | res = DIGIT(a, i); | |
32 | ||
33 | #if DIGIT_BIT < 64 | |
34 | while (--i >= 0) { | |
35 | res = (res << DIGIT_BIT) | DIGIT(a, i); | |
36 | } | |
37 | #endif | |
38 | return res; | |
39 | } | |
40 | #endif |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_GROW_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* grow as required */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_IMPORT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* based on gmp's mpz_import. |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_INIT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* init a new mp_int */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_INIT_COPY_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* creates "a" then copies b into it */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_INIT_MULTI_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
14 | ||
16 | 15 | #include <stdarg.h> |
17 | 16 | |
18 | 17 | int mp_init_multi(mp_int *mp, ...) |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_INIT_SET_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* initialize and set a digit */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_INIT_SET_INT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* initialize and set a digit */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_INIT_SIZE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* init an mp_init for a given size */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_INVMOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* hac 14.61, pp608 */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_INVMOD_SLOW_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* hac 14.61, pp608 */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_IS_SQUARE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* Check if remainders are possible squares - fast exclude non-squares */ |
74 | 72 | return res; |
75 | 73 | } |
76 | 74 | if ((res = mp_mod(arg, &t, &t)) != MP_OKAY) { |
77 | goto ERR; | |
75 | goto LBL_ERR; | |
78 | 76 | } |
79 | 77 | r = mp_get_int(&t); |
80 | 78 | /* Check for other prime modules, note it's not an ERROR but we must |
81 | * free "t" so the easiest way is to goto ERR. We know that res | |
79 | * free "t" so the easiest way is to goto LBL_ERR. We know that res | |
82 | 80 | * is already equal to MP_OKAY from the mp_mod call |
83 | 81 | */ |
84 | if (((1uL<<(r%11uL)) & 0x5C4uL) != 0uL) goto ERR; | |
85 | if (((1uL<<(r%13uL)) & 0x9E4uL) != 0uL) goto ERR; | |
86 | if (((1uL<<(r%17uL)) & 0x5CE8uL) != 0uL) goto ERR; | |
87 | if (((1uL<<(r%19uL)) & 0x4F50CuL) != 0uL) goto ERR; | |
88 | if (((1uL<<(r%23uL)) & 0x7ACCA0uL) != 0uL) goto ERR; | |
89 | if (((1uL<<(r%29uL)) & 0xC2EDD0CuL) != 0uL) goto ERR; | |
90 | if (((1uL<<(r%31uL)) & 0x6DE2B848uL) != 0uL) goto ERR; | |
82 | if (((1uL<<(r%11uL)) & 0x5C4uL) != 0uL) goto LBL_ERR; | |
83 | if (((1uL<<(r%13uL)) & 0x9E4uL) != 0uL) goto LBL_ERR; | |
84 | if (((1uL<<(r%17uL)) & 0x5CE8uL) != 0uL) goto LBL_ERR; | |
85 | if (((1uL<<(r%19uL)) & 0x4F50CuL) != 0uL) goto LBL_ERR; | |
86 | if (((1uL<<(r%23uL)) & 0x7ACCA0uL) != 0uL) goto LBL_ERR; | |
87 | if (((1uL<<(r%29uL)) & 0xC2EDD0CuL) != 0uL) goto LBL_ERR; | |
88 | if (((1uL<<(r%31uL)) & 0x6DE2B848uL) != 0uL) goto LBL_ERR; | |
91 | 89 | |
92 | 90 | /* Final check - is sqr(sqrt(arg)) == arg ? */ |
93 | 91 | if ((res = mp_sqrt(arg, &t)) != MP_OKAY) { |
94 | goto ERR; | |
92 | goto LBL_ERR; | |
95 | 93 | } |
96 | 94 | if ((res = mp_sqr(&t, &t)) != MP_OKAY) { |
97 | goto ERR; | |
95 | goto LBL_ERR; | |
98 | 96 | } |
99 | 97 | |
100 | 98 | *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO; |
101 | ERR: | |
99 | LBL_ERR: | |
102 | 100 | mp_clear(&t); |
103 | 101 | return res; |
104 | 102 | } |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_JACOBI_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* computes the jacobi c = (a | n) (or Legendre if n is prime) |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_KARATSUBA_MUL_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* c = |a| * |b| using Karatsuba Multiplication using |
59 | 57 | |
60 | 58 | /* init copy all the temps */ |
61 | 59 | if (mp_init_size(&x0, B) != MP_OKAY) |
62 | goto ERR; | |
60 | goto LBL_ERR; | |
63 | 61 | if (mp_init_size(&x1, a->used - B) != MP_OKAY) |
64 | 62 | goto X0; |
65 | 63 | if (mp_init_size(&y0, B) != MP_OKAY) |
163 | 161 | mp_clear(&x1); |
164 | 162 | X0: |
165 | 163 | mp_clear(&x0); |
166 | ERR: | |
164 | LBL_ERR: | |
167 | 165 | return err; |
168 | 166 | } |
169 | 167 | #endif |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_KARATSUBA_SQR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* Karatsuba squaring, computes b = a*a using three |
36 | 34 | |
37 | 35 | /* init copy all the temps */ |
38 | 36 | if (mp_init_size(&x0, B) != MP_OKAY) |
39 | goto ERR; | |
37 | goto LBL_ERR; | |
40 | 38 | if (mp_init_size(&x1, a->used - B) != MP_OKAY) |
41 | 39 | goto X0; |
42 | 40 | |
116 | 114 | mp_clear(&x1); |
117 | 115 | X0: |
118 | 116 | mp_clear(&x0); |
119 | ERR: | |
117 | LBL_ERR: | |
120 | 118 | return err; |
121 | 119 | } |
122 | 120 | #endif |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_LCM_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* computes least common multiple as |a*b|/(a, b) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_LSHD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* shift left a certain amount of digits */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MOD_2D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* calc a value mod 2**b */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MOD_D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | int mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c) |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MONTGOMERY_REDUCE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* computes xR**-1 == x (mod N) via Montgomery Reduction */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MONTGOMERY_SETUP_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* setups the montgomery reduction stuff */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MUL_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* high level multiplication (handles sign) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MUL_2_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* b = a*2 */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MUL_2D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* shift left by a certain bit count */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MUL_D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* multiply by a digit */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_MULMOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* d = a * b (mod c) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_N_ROOT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* wrapper function for mp_n_root_ex() |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_N_ROOT_EX_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* find the n'th root of an integer |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_NEG_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* b = -a */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_OR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* OR two ints together */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_PRIME_FERMAT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* performs one Fermat test. |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_PRIME_IS_DIVISIBLE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* determines if an integers is divisible by one |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_PRIME_IS_PRIME_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* performs a variable number of rounds of Miller-Rabin |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_PRIME_MILLER_RABIN_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* Miller-Rabin test of "a" to the base of "b" as described in |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_PRIME_NEXT_PRIME_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* finds the next prime after the number "a" using "t" trials |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_PRIME_RANDOM_EX_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* makes a truly random prime of a given size (bits), |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_RADIX_SIZE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* returns size of ASCII reprensentation */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_RADIX_SMAP_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* chars used in radix conversions */ |
18 | 16 | const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; |
19 | const uint8_t mp_s_rmap_reverse[] = { | |
20 | 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, /* ()*+,-./ */ | |
21 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 01234567 */ | |
22 | 0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 89:;<=>? */ | |
23 | 0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, /* @ABCDEFG */ | |
24 | 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, /* HIJKLMNO */ | |
25 | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, /* PQRSTUVW */ | |
26 | 0x21, 0x22, 0x23, 0xff, 0xff, 0xff, 0xff, 0xff, /* XYZ[\]^_ */ | |
27 | 0xff, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, /* `abcdefg */ | |
28 | 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, /* hijklmno */ | |
29 | 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, /* pqrstuvw */ | |
30 | 0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, /* xyz{|}~. */ | |
17 | const unsigned char mp_s_rmap_reverse[] = { | |
18 | 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, /* ()*+,-./ */ | |
19 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 01234567 */ | |
20 | 0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 89:;<=>? */ | |
21 | 0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, /* @ABCDEFG */ | |
22 | 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, /* HIJKLMNO */ | |
23 | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, /* PQRSTUVW */ | |
24 | 0x21, 0x22, 0x23, 0xff, 0xff, 0xff, 0xff, 0xff, /* XYZ[\]^_ */ | |
25 | 0xff, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, /* `abcdefg */ | |
26 | 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, /* hijklmno */ | |
27 | 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, /* pqrstuvw */ | |
28 | 0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, /* xyz{|}~. */ | |
31 | 29 | }; |
32 | 30 | const size_t mp_s_rmap_reverse_sz = sizeof(mp_s_rmap_reverse); |
33 | 31 | #endif |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_RAND_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | #if defined(MP_8BIT) || defined(MP_16BIT) | |
18 | #define MP_GEN_RANDOM_SHIFT DIGIT_BIT | |
19 | #else | |
20 | #if MP_GEN_RANDOM_MAX == 0xffffffffu | |
21 | #define MP_GEN_RANDOM_SHIFT 32 | |
22 | #elif MP_GEN_RANDOM_MAX == 32767 | |
23 | /* SHRT_MAX */ | |
24 | #define MP_GEN_RANDOM_SHIFT 15 | |
25 | #elif MP_GEN_RANDOM_MAX == 2147483647 | |
26 | /* INT_MAX */ | |
27 | #define MP_GEN_RANDOM_SHIFT 31 | |
28 | #elif !defined(MP_GEN_RANDOM_SHIFT) | |
29 | #error Thou shalt define their own valid MP_GEN_RANDOM_SHIFT | |
30 | #endif | |
31 | #endif | |
32 | ||
33 | /* makes a pseudo-random int of a given size */ | |
34 | static mp_digit s_gen_random(void) | |
15 | /* First the OS-specific special cases | |
16 | * - *BSD | |
17 | * - Windows | |
18 | */ | |
19 | #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) | |
20 | #define MP_ARC4RANDOM | |
21 | #define MP_GEN_RANDOM_MAX 0xffffffffu | |
22 | #define MP_GEN_RANDOM_SHIFT 32 | |
23 | ||
24 | static int s_read_arc4random(mp_digit* p) | |
35 | 25 | { |
36 | 26 | mp_digit d = 0, msk = 0; |
37 | 27 | do { |
38 | 28 | d <<= MP_GEN_RANDOM_SHIFT; |
39 | d |= ((mp_digit) MP_GEN_RANDOM()); | |
29 | d |= ((mp_digit) arc4random()); | |
40 | 30 | msk <<= MP_GEN_RANDOM_SHIFT; |
41 | 31 | msk |= (MP_MASK & MP_GEN_RANDOM_MAX); |
42 | 32 | } while ((MP_MASK & msk) != MP_MASK); |
43 | d &= MP_MASK; | |
44 | return d; | |
33 | *p = d; | |
34 | return MP_OKAY; | |
35 | } | |
36 | #endif | |
37 | ||
38 | #if defined(_WIN32) || defined(_WIN32_WCE) | |
39 | #define MP_WIN_CSP | |
40 | ||
41 | #ifndef _WIN32_WINNT | |
42 | #define _WIN32_WINNT 0x0400 | |
43 | #endif | |
44 | #ifdef _WIN32_WCE | |
45 | #define UNDER_CE | |
46 | #define ARM | |
47 | #endif | |
48 | ||
49 | #define WIN32_LEAN_AND_MEAN | |
50 | #include <windows.h> | |
51 | #include <wincrypt.h> | |
52 | ||
53 | static HCRYPTPROV hProv = 0; | |
54 | ||
55 | static void s_cleanup_win_csp(void) | |
56 | { | |
57 | CryptReleaseContext(hProv, 0); | |
58 | hProv = 0; | |
59 | } | |
60 | ||
61 | static int s_read_win_csp(mp_digit* p) | |
62 | { | |
63 | int ret = -1; | |
64 | if (hProv == 0) { | |
65 | if (!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, | |
66 | (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) && | |
67 | !CryptAcquireContext (&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, | |
68 | CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET)) { | |
69 | hProv = 0; | |
70 | return ret; | |
71 | } | |
72 | atexit(s_cleanup_win_csp); | |
73 | } | |
74 | if (CryptGenRandom(hProv, sizeof(*p), (void*)p) == TRUE) { | |
75 | ret = MP_OKAY; | |
76 | } | |
77 | return ret; | |
78 | } | |
79 | #endif /* WIN32 */ | |
80 | ||
81 | #if !defined(MP_WIN_CSP) && defined(__linux__) && defined(__GLIBC_PREREQ) | |
82 | #if __GLIBC_PREREQ(2, 25) | |
83 | #define MP_GETRANDOM | |
84 | #include <sys/random.h> | |
85 | #include <errno.h> | |
86 | ||
87 | static int s_read_getrandom(mp_digit* p) | |
88 | { | |
89 | int ret; | |
90 | do { | |
91 | ret = getrandom(p, sizeof(*p), 0); | |
92 | } while((ret == -1) && (errno == EINTR)); | |
93 | if (ret == sizeof(*p)) return MP_OKAY; | |
94 | return -1; | |
95 | } | |
96 | #endif | |
97 | #endif | |
98 | ||
99 | /* We assume all platforms besides windows provide "/dev/urandom". | |
100 | * In case yours doesn't, define MP_NO_DEV_URANDOM at compile-time. | |
101 | */ | |
102 | #if !defined(MP_WIN_CSP) && !defined(MP_NO_DEV_URANDOM) | |
103 | #ifndef MP_DEV_URANDOM | |
104 | #define MP_DEV_URANDOM "/dev/urandom" | |
105 | #endif | |
106 | #include <fcntl.h> | |
107 | #include <errno.h> | |
108 | #include <unistd.h> | |
109 | ||
110 | static int s_read_dev_urandom(mp_digit* p) | |
111 | { | |
112 | ssize_t r; | |
113 | int fd; | |
114 | do { | |
115 | fd = open(MP_DEV_URANDOM, O_RDONLY); | |
116 | } while((fd == -1) && (errno == EINTR)); | |
117 | if (fd == -1) return -1; | |
118 | do { | |
119 | r = read(fd, p, sizeof(*p)); | |
120 | } while((r == -1) && (errno == EINTR)); | |
121 | close(fd); | |
122 | if (r != sizeof(*p)) return -1; | |
123 | return MP_OKAY; | |
124 | } | |
125 | #endif | |
126 | ||
127 | #if defined(MP_PRNG_ENABLE_LTM_RNG) | |
128 | unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); | |
129 | void (*ltm_rng_callback)(void); | |
130 | ||
131 | static int s_read_ltm_rng(mp_digit* p) | |
132 | { | |
133 | unsigned long ret; | |
134 | if (ltm_rng == NULL) return -1; | |
135 | ret = ltm_rng((void*)p, sizeof(*p), ltm_rng_callback); | |
136 | if (ret != sizeof(*p)) return -1; | |
137 | return MP_OKAY; | |
138 | } | |
139 | #endif | |
140 | ||
141 | static int s_rand_digit(mp_digit* p) | |
142 | { | |
143 | int ret = -1; | |
144 | ||
145 | #if defined(MP_ARC4RANDOM) | |
146 | ret = s_read_arc4random(p); | |
147 | if (ret == MP_OKAY) return ret; | |
148 | #endif | |
149 | ||
150 | #if defined(MP_WIN_CSP) | |
151 | ret = s_read_win_csp(p); | |
152 | if (ret == MP_OKAY) return ret; | |
153 | #else | |
154 | ||
155 | #if defined(MP_GETRANDOM) | |
156 | ret = s_read_getrandom(p); | |
157 | if (ret == MP_OKAY) return ret; | |
158 | #endif | |
159 | #if defined(MP_DEV_URANDOM) | |
160 | ret = s_read_dev_urandom(p); | |
161 | if (ret == MP_OKAY) return ret; | |
162 | #endif | |
163 | ||
164 | #endif /* MP_WIN_CSP */ | |
165 | ||
166 | #if defined(MP_PRNG_ENABLE_LTM_RNG) | |
167 | ret = s_read_ltm_rng(p); | |
168 | if (ret == MP_OKAY) return ret; | |
169 | #endif | |
170 | ||
171 | return ret; | |
172 | } | |
173 | ||
174 | /* makes a pseudo-random int of a given size */ | |
175 | static int s_gen_random(mp_digit *r) | |
176 | { | |
177 | int ret = s_rand_digit(r); | |
178 | *r &= MP_MASK; | |
179 | return ret; | |
45 | 180 | } |
46 | 181 | |
47 | 182 | int mp_rand(mp_int *a, int digits) |
56 | 191 | |
57 | 192 | /* first place a random non-zero digit */ |
58 | 193 | do { |
59 | d = s_gen_random(); | |
194 | if (s_gen_random(&d) != MP_OKAY) { | |
195 | return MP_VAL; | |
196 | } | |
60 | 197 | } while (d == 0u); |
61 | 198 | |
62 | 199 | if ((res = mp_add_d(a, d, a)) != MP_OKAY) { |
68 | 205 | return res; |
69 | 206 | } |
70 | 207 | |
71 | if ((res = mp_add_d(a, s_gen_random(), a)) != MP_OKAY) { | |
208 | if (s_gen_random(&d) != MP_OKAY) { | |
209 | return MP_VAL; | |
210 | } | |
211 | if ((res = mp_add_d(a, d, a)) != MP_OKAY) { | |
72 | 212 | return res; |
73 | 213 | } |
74 | 214 | } |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_READ_RADIX_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* read a string [ASCII] in a given radix */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_READ_SIGNED_BIN_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* read signed bin, big endian, first byte is 0==positive or 1==negative */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_READ_UNSIGNED_BIN_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* reads a unsigned char array, assumes the msb is stored first [big endian] */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_REDUCE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* reduces x mod m, assumes 0 < x < m**2, mu is |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_REDUCE_2K_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* reduces a modulo n where n is of the form 2**p - d */ |
28 | 26 | top: |
29 | 27 | /* q = a/2**p, a = a mod 2**p */ |
30 | 28 | if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) { |
31 | goto ERR; | |
29 | goto LBL_ERR; | |
32 | 30 | } |
33 | 31 | |
34 | 32 | if (d != 1u) { |
35 | 33 | /* q = q * d */ |
36 | 34 | if ((res = mp_mul_d(&q, d, &q)) != MP_OKAY) { |
37 | goto ERR; | |
35 | goto LBL_ERR; | |
38 | 36 | } |
39 | 37 | } |
40 | 38 | |
41 | 39 | /* a = a + q */ |
42 | 40 | if ((res = s_mp_add(a, &q, a)) != MP_OKAY) { |
43 | goto ERR; | |
41 | goto LBL_ERR; | |
44 | 42 | } |
45 | 43 | |
46 | 44 | if (mp_cmp_mag(a, n) != MP_LT) { |
47 | 45 | if ((res = s_mp_sub(a, n, a)) != MP_OKAY) { |
48 | goto ERR; | |
46 | goto LBL_ERR; | |
49 | 47 | } |
50 | 48 | goto top; |
51 | 49 | } |
52 | 50 | |
53 | ERR: | |
51 | LBL_ERR: | |
54 | 52 | mp_clear(&q); |
55 | 53 | return res; |
56 | 54 | } |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_REDUCE_2K_L_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* reduces a modulo n where n is of the form 2**p - d |
31 | 29 | top: |
32 | 30 | /* q = a/2**p, a = a mod 2**p */ |
33 | 31 | if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) { |
34 | goto ERR; | |
32 | goto LBL_ERR; | |
35 | 33 | } |
36 | 34 | |
37 | 35 | /* q = q * d */ |
38 | 36 | if ((res = mp_mul(&q, d, &q)) != MP_OKAY) { |
39 | goto ERR; | |
37 | goto LBL_ERR; | |
40 | 38 | } |
41 | 39 | |
42 | 40 | /* a = a + q */ |
43 | 41 | if ((res = s_mp_add(a, &q, a)) != MP_OKAY) { |
44 | goto ERR; | |
42 | goto LBL_ERR; | |
45 | 43 | } |
46 | 44 | |
47 | 45 | if (mp_cmp_mag(a, n) != MP_LT) { |
48 | 46 | if ((res = s_mp_sub(a, n, a)) != MP_OKAY) { |
49 | goto ERR; | |
47 | goto LBL_ERR; | |
50 | 48 | } |
51 | 49 | goto top; |
52 | 50 | } |
53 | 51 | |
54 | ERR: | |
52 | LBL_ERR: | |
55 | 53 | mp_clear(&q); |
56 | 54 | return res; |
57 | 55 | } |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_REDUCE_2K_SETUP_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* determines the setup value */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_REDUCE_2K_SETUP_L_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* determines the setup value */ |
25 | 23 | } |
26 | 24 | |
27 | 25 | if ((res = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) { |
28 | goto ERR; | |
26 | goto LBL_ERR; | |
29 | 27 | } |
30 | 28 | |
31 | 29 | if ((res = s_mp_sub(&tmp, a, d)) != MP_OKAY) { |
32 | goto ERR; | |
30 | goto LBL_ERR; | |
33 | 31 | } |
34 | 32 | |
35 | ERR: | |
33 | LBL_ERR: | |
36 | 34 | mp_clear(&tmp); |
37 | 35 | return res; |
38 | 36 | } |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_REDUCE_IS_2K_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* determines if mp_reduce_2k can be used */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_REDUCE_IS_2K_L_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* determines if reduce_2k_l can be used */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_REDUCE_SETUP_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* pre-calculate the value required for Barrett reduction |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_RSHD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* shift right a certain amount of digits */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SET_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* set to a digit */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SET_INT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* set a 32-bit const */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SET_LONG_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* set a platform dependent unsigned long int */ |
0 | #include <tommath_private.h> | |
1 | #ifdef BN_MP_SET_LONG_LONG_C | |
2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis | |
3 | * | |
4 | * LibTomMath is a library that provides multiple-precision | |
5 | * integer arithmetic as well as number theoretic functionality. | |
6 | * | |
7 | * The library was designed directly after the MPI library by | |
8 | * Michael Fromberger but has been written from scratch with | |
9 | * additional optimizations in place. | |
10 | * | |
11 | * The library is free for all purposes without any express | |
12 | * guarantee it works. | |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | */ | |
16 | ||
17 | /* set a platform dependent unsigned long long int */ | |
18 | MP_SET_XLONG(mp_set_long_long, uint64_t) | |
19 | #endif | |
20 | ||
21 | /* ref: $Format:%D$ */ | |
22 | /* git commit: $Format:%H$ */ | |
23 | /* commit time: $Format:%ai$ */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SHRINK_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* shrink a bignum */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SIGNED_BIN_SIZE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* get the size for an signed equivalent */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SQR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* computes b = a*a */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SQRMOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* c = a * a (mod b) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SQRT_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* this function is less generic than mp_n_root, simpler and faster */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SQRTMOD_PRIME_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SUB_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* high level subtraction (handles signs) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SUB_D_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* single digit subtraction */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_SUBMOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* d = a - b (mod c) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_TO_SIGNED_BIN_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* store in signed [big endian] format */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_TO_SIGNED_BIN_N_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* store in signed [big endian] format */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_TO_UNSIGNED_BIN_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* store in unsigned [big endian] format */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_TO_UNSIGNED_BIN_N_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* store in unsigned [big endian] format */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_TOOM_MUL_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* multiplication using the Toom-Cook 3-way algorithm |
38 | 36 | |
39 | 37 | /* a = a2 * B**2 + a1 * B + a0 */ |
40 | 38 | if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) { |
41 | goto ERR; | |
39 | goto LBL_ERR; | |
42 | 40 | } |
43 | 41 | |
44 | 42 | if ((res = mp_copy(a, &a1)) != MP_OKAY) { |
45 | goto ERR; | |
43 | goto LBL_ERR; | |
46 | 44 | } |
47 | 45 | mp_rshd(&a1, B); |
48 | 46 | if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) { |
49 | goto ERR; | |
47 | goto LBL_ERR; | |
50 | 48 | } |
51 | 49 | |
52 | 50 | if ((res = mp_copy(a, &a2)) != MP_OKAY) { |
53 | goto ERR; | |
51 | goto LBL_ERR; | |
54 | 52 | } |
55 | 53 | mp_rshd(&a2, B*2); |
56 | 54 | |
57 | 55 | /* b = b2 * B**2 + b1 * B + b0 */ |
58 | 56 | if ((res = mp_mod_2d(b, DIGIT_BIT * B, &b0)) != MP_OKAY) { |
59 | goto ERR; | |
57 | goto LBL_ERR; | |
60 | 58 | } |
61 | 59 | |
62 | 60 | if ((res = mp_copy(b, &b1)) != MP_OKAY) { |
63 | goto ERR; | |
61 | goto LBL_ERR; | |
64 | 62 | } |
65 | 63 | mp_rshd(&b1, B); |
66 | 64 | (void)mp_mod_2d(&b1, DIGIT_BIT * B, &b1); |
67 | 65 | |
68 | 66 | if ((res = mp_copy(b, &b2)) != MP_OKAY) { |
69 | goto ERR; | |
67 | goto LBL_ERR; | |
70 | 68 | } |
71 | 69 | mp_rshd(&b2, B*2); |
72 | 70 | |
73 | 71 | /* w0 = a0*b0 */ |
74 | 72 | if ((res = mp_mul(&a0, &b0, &w0)) != MP_OKAY) { |
75 | goto ERR; | |
73 | goto LBL_ERR; | |
76 | 74 | } |
77 | 75 | |
78 | 76 | /* w4 = a2 * b2 */ |
79 | 77 | if ((res = mp_mul(&a2, &b2, &w4)) != MP_OKAY) { |
80 | goto ERR; | |
78 | goto LBL_ERR; | |
81 | 79 | } |
82 | 80 | |
83 | 81 | /* w1 = (a2 + 2(a1 + 2a0))(b2 + 2(b1 + 2b0)) */ |
84 | 82 | if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { |
85 | goto ERR; | |
83 | goto LBL_ERR; | |
86 | 84 | } |
87 | 85 | if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { |
88 | goto ERR; | |
86 | goto LBL_ERR; | |
89 | 87 | } |
90 | 88 | if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { |
91 | goto ERR; | |
89 | goto LBL_ERR; | |
92 | 90 | } |
93 | 91 | if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { |
94 | goto ERR; | |
92 | goto LBL_ERR; | |
95 | 93 | } |
96 | 94 | |
97 | 95 | if ((res = mp_mul_2(&b0, &tmp2)) != MP_OKAY) { |
98 | goto ERR; | |
96 | goto LBL_ERR; | |
99 | 97 | } |
100 | 98 | if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) { |
101 | goto ERR; | |
99 | goto LBL_ERR; | |
102 | 100 | } |
103 | 101 | if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) { |
104 | goto ERR; | |
102 | goto LBL_ERR; | |
105 | 103 | } |
106 | 104 | if ((res = mp_add(&tmp2, &b2, &tmp2)) != MP_OKAY) { |
107 | goto ERR; | |
105 | goto LBL_ERR; | |
108 | 106 | } |
109 | 107 | |
110 | 108 | if ((res = mp_mul(&tmp1, &tmp2, &w1)) != MP_OKAY) { |
111 | goto ERR; | |
109 | goto LBL_ERR; | |
112 | 110 | } |
113 | 111 | |
114 | 112 | /* w3 = (a0 + 2(a1 + 2a2))(b0 + 2(b1 + 2b2)) */ |
115 | 113 | if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { |
116 | goto ERR; | |
114 | goto LBL_ERR; | |
117 | 115 | } |
118 | 116 | if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { |
119 | goto ERR; | |
117 | goto LBL_ERR; | |
120 | 118 | } |
121 | 119 | if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { |
122 | goto ERR; | |
120 | goto LBL_ERR; | |
123 | 121 | } |
124 | 122 | if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { |
125 | goto ERR; | |
123 | goto LBL_ERR; | |
126 | 124 | } |
127 | 125 | |
128 | 126 | if ((res = mp_mul_2(&b2, &tmp2)) != MP_OKAY) { |
129 | goto ERR; | |
127 | goto LBL_ERR; | |
130 | 128 | } |
131 | 129 | if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) { |
132 | goto ERR; | |
130 | goto LBL_ERR; | |
133 | 131 | } |
134 | 132 | if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) { |
135 | goto ERR; | |
133 | goto LBL_ERR; | |
136 | 134 | } |
137 | 135 | if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) { |
138 | goto ERR; | |
136 | goto LBL_ERR; | |
139 | 137 | } |
140 | 138 | |
141 | 139 | if ((res = mp_mul(&tmp1, &tmp2, &w3)) != MP_OKAY) { |
142 | goto ERR; | |
140 | goto LBL_ERR; | |
143 | 141 | } |
144 | 142 | |
145 | 143 | |
146 | 144 | /* w2 = (a2 + a1 + a0)(b2 + b1 + b0) */ |
147 | 145 | if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { |
148 | goto ERR; | |
146 | goto LBL_ERR; | |
149 | 147 | } |
150 | 148 | if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { |
151 | goto ERR; | |
149 | goto LBL_ERR; | |
152 | 150 | } |
153 | 151 | if ((res = mp_add(&b2, &b1, &tmp2)) != MP_OKAY) { |
154 | goto ERR; | |
152 | goto LBL_ERR; | |
155 | 153 | } |
156 | 154 | if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) { |
157 | goto ERR; | |
155 | goto LBL_ERR; | |
158 | 156 | } |
159 | 157 | if ((res = mp_mul(&tmp1, &tmp2, &w2)) != MP_OKAY) { |
160 | goto ERR; | |
158 | goto LBL_ERR; | |
161 | 159 | } |
162 | 160 | |
163 | 161 | /* now solve the matrix |
174 | 172 | |
175 | 173 | /* r1 - r4 */ |
176 | 174 | if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { |
177 | goto ERR; | |
175 | goto LBL_ERR; | |
178 | 176 | } |
179 | 177 | /* r3 - r0 */ |
180 | 178 | if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { |
181 | goto ERR; | |
179 | goto LBL_ERR; | |
182 | 180 | } |
183 | 181 | /* r1/2 */ |
184 | 182 | if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) { |
185 | goto ERR; | |
183 | goto LBL_ERR; | |
186 | 184 | } |
187 | 185 | /* r3/2 */ |
188 | 186 | if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) { |
189 | goto ERR; | |
187 | goto LBL_ERR; | |
190 | 188 | } |
191 | 189 | /* r2 - r0 - r4 */ |
192 | 190 | if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { |
193 | goto ERR; | |
191 | goto LBL_ERR; | |
194 | 192 | } |
195 | 193 | if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { |
196 | goto ERR; | |
194 | goto LBL_ERR; | |
197 | 195 | } |
198 | 196 | /* r1 - r2 */ |
199 | 197 | if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { |
200 | goto ERR; | |
198 | goto LBL_ERR; | |
201 | 199 | } |
202 | 200 | /* r3 - r2 */ |
203 | 201 | if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { |
204 | goto ERR; | |
202 | goto LBL_ERR; | |
205 | 203 | } |
206 | 204 | /* r1 - 8r0 */ |
207 | 205 | if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { |
208 | goto ERR; | |
206 | goto LBL_ERR; | |
209 | 207 | } |
210 | 208 | if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { |
211 | goto ERR; | |
209 | goto LBL_ERR; | |
212 | 210 | } |
213 | 211 | /* r3 - 8r4 */ |
214 | 212 | if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { |
215 | goto ERR; | |
213 | goto LBL_ERR; | |
216 | 214 | } |
217 | 215 | if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { |
218 | goto ERR; | |
216 | goto LBL_ERR; | |
219 | 217 | } |
220 | 218 | /* 3r2 - r1 - r3 */ |
221 | 219 | if ((res = mp_mul_d(&w2, 3uL, &w2)) != MP_OKAY) { |
222 | goto ERR; | |
220 | goto LBL_ERR; | |
223 | 221 | } |
224 | 222 | if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { |
225 | goto ERR; | |
223 | goto LBL_ERR; | |
226 | 224 | } |
227 | 225 | if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { |
228 | goto ERR; | |
226 | goto LBL_ERR; | |
229 | 227 | } |
230 | 228 | /* r1 - r2 */ |
231 | 229 | if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { |
232 | goto ERR; | |
230 | goto LBL_ERR; | |
233 | 231 | } |
234 | 232 | /* r3 - r2 */ |
235 | 233 | if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { |
236 | goto ERR; | |
234 | goto LBL_ERR; | |
237 | 235 | } |
238 | 236 | /* r1/3 */ |
239 | 237 | if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { |
240 | goto ERR; | |
238 | goto LBL_ERR; | |
241 | 239 | } |
242 | 240 | /* r3/3 */ |
243 | 241 | if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { |
244 | goto ERR; | |
242 | goto LBL_ERR; | |
245 | 243 | } |
246 | 244 | |
247 | 245 | /* at this point shift W[n] by B*n */ |
248 | 246 | if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) { |
249 | goto ERR; | |
247 | goto LBL_ERR; | |
250 | 248 | } |
251 | 249 | if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) { |
252 | goto ERR; | |
250 | goto LBL_ERR; | |
253 | 251 | } |
254 | 252 | if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) { |
255 | goto ERR; | |
253 | goto LBL_ERR; | |
256 | 254 | } |
257 | 255 | if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) { |
258 | goto ERR; | |
256 | goto LBL_ERR; | |
259 | 257 | } |
260 | 258 | |
261 | 259 | if ((res = mp_add(&w0, &w1, c)) != MP_OKAY) { |
262 | goto ERR; | |
260 | goto LBL_ERR; | |
263 | 261 | } |
264 | 262 | if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { |
265 | goto ERR; | |
263 | goto LBL_ERR; | |
266 | 264 | } |
267 | 265 | if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { |
268 | goto ERR; | |
266 | goto LBL_ERR; | |
269 | 267 | } |
270 | 268 | if ((res = mp_add(&tmp1, c, c)) != MP_OKAY) { |
271 | goto ERR; | |
272 | } | |
273 | ||
274 | ERR: | |
269 | goto LBL_ERR; | |
270 | } | |
271 | ||
272 | LBL_ERR: | |
275 | 273 | mp_clear_multi(&w0, &w1, &w2, &w3, &w4, |
276 | 274 | &a0, &a1, &a2, &b0, &b1, |
277 | 275 | &b2, &tmp1, &tmp2, NULL); |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_TOOM_SQR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* squaring using Toom-Cook 3-way algorithm */ |
30 | 28 | |
31 | 29 | /* a = a2 * B**2 + a1 * B + a0 */ |
32 | 30 | if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) { |
33 | goto ERR; | |
31 | goto LBL_ERR; | |
34 | 32 | } |
35 | 33 | |
36 | 34 | if ((res = mp_copy(a, &a1)) != MP_OKAY) { |
37 | goto ERR; | |
35 | goto LBL_ERR; | |
38 | 36 | } |
39 | 37 | mp_rshd(&a1, B); |
40 | 38 | if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) { |
41 | goto ERR; | |
39 | goto LBL_ERR; | |
42 | 40 | } |
43 | 41 | |
44 | 42 | if ((res = mp_copy(a, &a2)) != MP_OKAY) { |
45 | goto ERR; | |
43 | goto LBL_ERR; | |
46 | 44 | } |
47 | 45 | mp_rshd(&a2, B*2); |
48 | 46 | |
49 | 47 | /* w0 = a0*a0 */ |
50 | 48 | if ((res = mp_sqr(&a0, &w0)) != MP_OKAY) { |
51 | goto ERR; | |
49 | goto LBL_ERR; | |
52 | 50 | } |
53 | 51 | |
54 | 52 | /* w4 = a2 * a2 */ |
55 | 53 | if ((res = mp_sqr(&a2, &w4)) != MP_OKAY) { |
56 | goto ERR; | |
54 | goto LBL_ERR; | |
57 | 55 | } |
58 | 56 | |
59 | 57 | /* w1 = (a2 + 2(a1 + 2a0))**2 */ |
60 | 58 | if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { |
61 | goto ERR; | |
59 | goto LBL_ERR; | |
62 | 60 | } |
63 | 61 | if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { |
64 | goto ERR; | |
62 | goto LBL_ERR; | |
65 | 63 | } |
66 | 64 | if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { |
67 | goto ERR; | |
65 | goto LBL_ERR; | |
68 | 66 | } |
69 | 67 | if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { |
70 | goto ERR; | |
68 | goto LBL_ERR; | |
71 | 69 | } |
72 | 70 | |
73 | 71 | if ((res = mp_sqr(&tmp1, &w1)) != MP_OKAY) { |
74 | goto ERR; | |
72 | goto LBL_ERR; | |
75 | 73 | } |
76 | 74 | |
77 | 75 | /* w3 = (a0 + 2(a1 + 2a2))**2 */ |
78 | 76 | if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { |
79 | goto ERR; | |
77 | goto LBL_ERR; | |
80 | 78 | } |
81 | 79 | if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { |
82 | goto ERR; | |
80 | goto LBL_ERR; | |
83 | 81 | } |
84 | 82 | if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { |
85 | goto ERR; | |
83 | goto LBL_ERR; | |
86 | 84 | } |
87 | 85 | if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { |
88 | goto ERR; | |
86 | goto LBL_ERR; | |
89 | 87 | } |
90 | 88 | |
91 | 89 | if ((res = mp_sqr(&tmp1, &w3)) != MP_OKAY) { |
92 | goto ERR; | |
90 | goto LBL_ERR; | |
93 | 91 | } |
94 | 92 | |
95 | 93 | |
96 | 94 | /* w2 = (a2 + a1 + a0)**2 */ |
97 | 95 | if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { |
98 | goto ERR; | |
96 | goto LBL_ERR; | |
99 | 97 | } |
100 | 98 | if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { |
101 | goto ERR; | |
99 | goto LBL_ERR; | |
102 | 100 | } |
103 | 101 | if ((res = mp_sqr(&tmp1, &w2)) != MP_OKAY) { |
104 | goto ERR; | |
102 | goto LBL_ERR; | |
105 | 103 | } |
106 | 104 | |
107 | 105 | /* now solve the matrix |
117 | 115 | |
118 | 116 | /* r1 - r4 */ |
119 | 117 | if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { |
120 | goto ERR; | |
118 | goto LBL_ERR; | |
121 | 119 | } |
122 | 120 | /* r3 - r0 */ |
123 | 121 | if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { |
124 | goto ERR; | |
122 | goto LBL_ERR; | |
125 | 123 | } |
126 | 124 | /* r1/2 */ |
127 | 125 | if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) { |
128 | goto ERR; | |
126 | goto LBL_ERR; | |
129 | 127 | } |
130 | 128 | /* r3/2 */ |
131 | 129 | if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) { |
132 | goto ERR; | |
130 | goto LBL_ERR; | |
133 | 131 | } |
134 | 132 | /* r2 - r0 - r4 */ |
135 | 133 | if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { |
136 | goto ERR; | |
134 | goto LBL_ERR; | |
137 | 135 | } |
138 | 136 | if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { |
139 | goto ERR; | |
137 | goto LBL_ERR; | |
140 | 138 | } |
141 | 139 | /* r1 - r2 */ |
142 | 140 | if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { |
143 | goto ERR; | |
141 | goto LBL_ERR; | |
144 | 142 | } |
145 | 143 | /* r3 - r2 */ |
146 | 144 | if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { |
147 | goto ERR; | |
145 | goto LBL_ERR; | |
148 | 146 | } |
149 | 147 | /* r1 - 8r0 */ |
150 | 148 | if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { |
151 | goto ERR; | |
149 | goto LBL_ERR; | |
152 | 150 | } |
153 | 151 | if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { |
154 | goto ERR; | |
152 | goto LBL_ERR; | |
155 | 153 | } |
156 | 154 | /* r3 - 8r4 */ |
157 | 155 | if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { |
158 | goto ERR; | |
156 | goto LBL_ERR; | |
159 | 157 | } |
160 | 158 | if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { |
161 | goto ERR; | |
159 | goto LBL_ERR; | |
162 | 160 | } |
163 | 161 | /* 3r2 - r1 - r3 */ |
164 | 162 | if ((res = mp_mul_d(&w2, 3uL, &w2)) != MP_OKAY) { |
165 | goto ERR; | |
163 | goto LBL_ERR; | |
166 | 164 | } |
167 | 165 | if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { |
168 | goto ERR; | |
166 | goto LBL_ERR; | |
169 | 167 | } |
170 | 168 | if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { |
171 | goto ERR; | |
169 | goto LBL_ERR; | |
172 | 170 | } |
173 | 171 | /* r1 - r2 */ |
174 | 172 | if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { |
175 | goto ERR; | |
173 | goto LBL_ERR; | |
176 | 174 | } |
177 | 175 | /* r3 - r2 */ |
178 | 176 | if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { |
179 | goto ERR; | |
177 | goto LBL_ERR; | |
180 | 178 | } |
181 | 179 | /* r1/3 */ |
182 | 180 | if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { |
183 | goto ERR; | |
181 | goto LBL_ERR; | |
184 | 182 | } |
185 | 183 | /* r3/3 */ |
186 | 184 | if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { |
187 | goto ERR; | |
185 | goto LBL_ERR; | |
188 | 186 | } |
189 | 187 | |
190 | 188 | /* at this point shift W[n] by B*n */ |
191 | 189 | if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) { |
192 | goto ERR; | |
190 | goto LBL_ERR; | |
193 | 191 | } |
194 | 192 | if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) { |
195 | goto ERR; | |
193 | goto LBL_ERR; | |
196 | 194 | } |
197 | 195 | if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) { |
198 | goto ERR; | |
196 | goto LBL_ERR; | |
199 | 197 | } |
200 | 198 | if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) { |
201 | goto ERR; | |
199 | goto LBL_ERR; | |
202 | 200 | } |
203 | 201 | |
204 | 202 | if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) { |
205 | goto ERR; | |
203 | goto LBL_ERR; | |
206 | 204 | } |
207 | 205 | if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { |
208 | goto ERR; | |
206 | goto LBL_ERR; | |
209 | 207 | } |
210 | 208 | if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { |
211 | goto ERR; | |
209 | goto LBL_ERR; | |
212 | 210 | } |
213 | 211 | if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) { |
214 | goto ERR; | |
215 | } | |
216 | ||
217 | ERR: | |
212 | goto LBL_ERR; | |
213 | } | |
214 | ||
215 | LBL_ERR: | |
218 | 216 | mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL); |
219 | 217 | return res; |
220 | 218 | } |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_TORADIX_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* stores a bignum as a ASCII string in a given radix (2..64) */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_TORADIX_N_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* stores a bignum as a ASCII string in a given radix (2..64) |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_UNSIGNED_BIN_SIZE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* get the size for an unsigned equivalent */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_XOR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* XOR two ints together */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_MP_ZERO_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* set to zero */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_PRIME_TAB_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
14 | ||
16 | 15 | const mp_digit ltm_prime_tab[] = { |
17 | 16 | 0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013, |
18 | 17 | 0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035, |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_REVERSE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* reverse an array, used for radix code */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_S_MP_ADD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* low level addition, based on HAC pp.594, Algorithm 14.7 */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_S_MP_EXPTMOD_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
14 | ||
16 | 15 | #ifdef MP_LOW_MEM |
17 | 16 | # define TAB_SIZE 32 |
18 | 17 | #else |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_S_MP_MUL_DIGS_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* multiplies |a| * |b| and only computes upto digs digits of result |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_S_MP_MUL_HIGH_DIGS_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* multiplies |a| * |b| and does not compute the lower digs digits |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_S_MP_SQR_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BN_S_MP_SUB_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */ |
0 | #include <tommath_private.h> | |
0 | #include "tommath_private.h" | |
1 | 1 | #ifdef BNCORE_C |
2 | 2 | /* LibTomMath, multiple-precision integer library -- Tom St Denis |
3 | 3 | * |
10 | 10 | * |
11 | 11 | * The library is free for all purposes without any express |
12 | 12 | * guarantee it works. |
13 | * | |
14 | * Tom St Denis, tstdenis82@gmail.com, http://libtom.org | |
15 | 13 | */ |
16 | 14 | |
17 | 15 | /* Known optimal configurations |
8 | 8 | * |
9 | 9 | * The library is free for all purposes without any express |
10 | 10 | * guarantee it works. |
11 | * | |
12 | * Tom St Denis, tstdenis82@gmail.com, http://math.libtomcrypt.com | |
13 | 11 | */ |
14 | 12 | #ifndef BN_H_ |
15 | 13 | #define BN_H_ |
18 | 16 | #include <stdlib.h> |
19 | 17 | #include <limits.h> |
20 | 18 | |
21 | #if !defined(_MSC_VER) || _MSC_VER >= 1600 | |
22 | /* supported since Microsoft Visual Studio 2010 */ | |
23 | #include <stdint.h> | |
24 | #else | |
25 | typedef signed char int8_t; | |
26 | typedef unsigned char uint8_t; | |
27 | typedef signed short int16_t; | |
28 | typedef unsigned short uint16_t; | |
29 | typedef signed int int32_t; | |
30 | typedef unsigned int uint32_t; | |
31 | # ifdef _MSC_VER | |
32 | /* long long does not work before MS Visual C++ 7.0 */ | |
33 | typedef signed __int64 int64_t; | |
34 | typedef unsigned __int64 uint64_t; | |
35 | # else | |
36 | typedef long long int64_t; | |
37 | typedef unsigned long long uint64_t; | |
38 | # endif | |
39 | #endif | |
40 | ||
41 | 19 | #include <tommath_class.h> |
42 | 20 | |
43 | 21 | #ifdef __cplusplus |
45 | 23 | #endif |
46 | 24 | |
47 | 25 | /* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */ |
48 | #if defined(_MSC_VER) || defined(__LLP64__) | |
26 | #if defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__) | |
49 | 27 | # define MP_32BIT |
50 | 28 | #endif |
51 | 29 | |
57 | 35 | defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \ |
58 | 36 | defined(__LP64__) || defined(_LP64) || defined(__64BIT__) |
59 | 37 | # if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT)) |
60 | # define MP_64BIT | |
38 | # if defined(__GNUC__) | |
39 | /* we support 128bit integers only via: __attribute__((mode(TI))) */ | |
40 | # define MP_64BIT | |
41 | # else | |
42 | /* otherwise we fall back to MP_32BIT even on 64bit platforms */ | |
43 | # define MP_32BIT | |
44 | # endif | |
61 | 45 | # endif |
62 | 46 | #endif |
63 | 47 | |
70 | 54 | * [any size beyond that is ok provided it doesn't overflow the data type] |
71 | 55 | */ |
72 | 56 | #ifdef MP_8BIT |
73 | typedef uint8_t mp_digit; | |
74 | typedef uint16_t mp_word; | |
57 | typedef unsigned char mp_digit; | |
58 | typedef unsigned short mp_word; | |
75 | 59 | # define MP_SIZEOF_MP_DIGIT 1 |
76 | 60 | # ifdef DIGIT_BIT |
77 | 61 | # error You must not define DIGIT_BIT when using MP_8BIT |
78 | 62 | # endif |
79 | 63 | #elif defined(MP_16BIT) |
80 | typedef uint16_t mp_digit; | |
81 | typedef uint32_t mp_word; | |
64 | typedef unsigned short mp_digit; | |
65 | typedef unsigned int mp_word; | |
82 | 66 | # define MP_SIZEOF_MP_DIGIT 2 |
83 | 67 | # ifdef DIGIT_BIT |
84 | 68 | # error You must not define DIGIT_BIT when using MP_16BIT |
85 | 69 | # endif |
86 | 70 | #elif defined(MP_64BIT) |
87 | 71 | /* for GCC only on supported platforms */ |
88 | typedef uint64_t mp_digit; | |
89 | # if defined(__GNUC__) | |
72 | typedef unsigned long long mp_digit; | |
90 | 73 | typedef unsigned long mp_word __attribute__((mode(TI))); |
91 | # else | |
92 | /* it seems you have a problem | |
93 | * but we assume you can somewhere define your own uint128_t */ | |
94 | typedef uint128_t mp_word; | |
95 | # endif | |
96 | ||
97 | 74 | # define DIGIT_BIT 60 |
98 | 75 | #else |
99 | 76 | /* this is the default case, 28-bit digits */ |
100 | 77 | |
101 | 78 | /* this is to make porting into LibTomCrypt easier :-) */ |
102 | typedef uint32_t mp_digit; | |
103 | typedef uint64_t mp_word; | |
79 | typedef unsigned int mp_digit; | |
80 | #ifdef _MSC_VER | |
81 | typedef unsigned __int64 mp_word; | |
82 | #else | |
83 | typedef unsigned long long mp_word; /* PATCHED */ | |
84 | #endif | |
104 | 85 | |
105 | 86 | # ifdef MP_31BIT |
106 | 87 | /* this is an extension that uses 31-bit digits */ |
115 | 96 | /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ |
116 | 97 | #ifndef DIGIT_BIT |
117 | 98 | # define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ |
118 | typedef uint_least32_t mp_min_u32; | |
99 | typedef unsigned long mp_min_u32; | |
119 | 100 | #else |
120 | 101 | typedef mp_digit mp_min_u32; |
121 | #endif | |
122 | ||
123 | /* use arc4random on platforms that support it */ | |
124 | #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) | |
125 | # define MP_GEN_RANDOM() arc4random() | |
126 | # define MP_GEN_RANDOM_MAX 0xffffffffu | |
127 | #endif | |
128 | ||
129 | /* use rand() as fall-back if there's no better rand function */ | |
130 | #ifndef MP_GEN_RANDOM | |
131 | # define MP_GEN_RANDOM() rand() | |
132 | # define MP_GEN_RANDOM_MAX RAND_MAX | |
133 | 102 | #endif |
134 | 103 | |
135 | 104 | #define MP_DIGIT_BIT DIGIT_BIT |
241 | 210 | int mp_set_long(mp_int *a, unsigned long b); |
242 | 211 | |
243 | 212 | /* set a platform dependent unsigned long long value */ |
244 | int mp_set_long_long(mp_int *a, uint64_t b); | |
213 | /* int mp_set_long_long(mp_int *a, unsigned long long b); */ | |
245 | 214 | |
246 | 215 | /* get a 32-bit value */ |
247 | 216 | unsigned long mp_get_int(const mp_int *a); |
250 | 219 | unsigned long mp_get_long(const mp_int *a); |
251 | 220 | |
252 | 221 | /* get a platform dependent unsigned long long value */ |
253 | uint64_t mp_get_long_long(const mp_int *a); | |
222 | /* unsigned long long mp_get_long_long(const mp_int *a); */ | |
254 | 223 | |
255 | 224 | /* initialize and set a digit */ |
256 | 225 | int mp_init_set(mp_int *a, mp_digit b); |
306 | 275 | |
307 | 276 | /* makes a pseudo-random int of a given size */ |
308 | 277 | int mp_rand(mp_int *a, int digits); |
278 | ||
279 | #ifdef MP_PRNG_ENABLE_LTM_RNG | |
280 | /* as last resort we will fall back to libtomcrypt's rng_get_bytes() | |
281 | * in case you don't use libtomcrypt or use it w/o rng_get_bytes() | |
282 | * you have to implement it somewhere else, as it's required */ | |
283 | extern unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); | |
284 | extern void (*ltm_rng_callback)(void); | |
285 | #endif | |
309 | 286 | |
310 | 287 | /* ---> binary operations <--- */ |
311 | 288 | /* c = a XOR b */ |
8 | 8 | * |
9 | 9 | * The library is free for all purposes without any express |
10 | 10 | * guarantee it works. |
11 | * | |
12 | * Tom St Denis, tstdenis82@gmail.com, http://math.libtomcrypt.com | |
13 | 11 | */ |
14 | 12 | #ifndef TOMMATH_PRIV_H_ |
15 | 13 | #define TOMMATH_PRIV_H_ |
16 | 14 | |
17 | #include <tommath.h> | |
15 | #include "tommath.h" | |
18 | 16 | #include <ctype.h> |
19 | 17 | |
20 | 18 | #ifndef MIN |
75 | 73 | void bn_reverse(unsigned char *s, int len); |
76 | 74 | |
77 | 75 | extern const char *mp_s_rmap; |
78 | extern const uint8_t mp_s_rmap_reverse[]; | |
76 | extern const unsigned char mp_s_rmap_reverse[]; | |
79 | 77 | extern const size_t mp_s_rmap_reverse_sz; |
80 | 78 | |
81 | 79 | /* Fancy macro to set an MPI from another type. |
10 | 10 | is( Crypt::Cipher::DES_EDE::blocksize, 8, '::blocksize'); |
11 | 11 | is( Crypt::Cipher::DES_EDE::keysize, 24, '::keysize'); |
12 | 12 | is( Crypt::Cipher::DES_EDE::max_keysize, 24, '::max_keysize'); |
13 | is( Crypt::Cipher::DES_EDE::min_keysize, 24, '::min_keysize'); | |
13 | is( Crypt::Cipher::DES_EDE::min_keysize, 16, '::min_keysize'); | |
14 | 14 | is( Crypt::Cipher::DES_EDE::default_rounds, 16, '::default_rounds'); |
15 | 15 | |
16 | 16 | is( Crypt::Cipher::DES_EDE->blocksize, 8, '->blocksize'); |
17 | 17 | is( Crypt::Cipher::DES_EDE->keysize, 24, '->keysize'); |
18 | 18 | is( Crypt::Cipher::DES_EDE->max_keysize, 24, '->max_keysize'); |
19 | is( Crypt::Cipher::DES_EDE->min_keysize, 24, '->min_keysize'); | |
19 | is( Crypt::Cipher::DES_EDE->min_keysize, 16, '->min_keysize'); | |
20 | 20 | is( Crypt::Cipher::DES_EDE->default_rounds, 16, '->default_rounds'); |
21 | 21 | |
22 | 22 | my $min_key = 'kkkkkkkkkkkkkkkkkkkkkkkk'; |
25 | 25 | is( Crypt::Cipher::blocksize('DES_EDE'), 8, 'Cipher->blocksize'); |
26 | 26 | is( Crypt::Cipher::keysize('DES_EDE'), 24, 'Cipher->keysize'); |
27 | 27 | is( Crypt::Cipher::max_keysize('DES_EDE'), 24, 'Cipher->max_keysize'); |
28 | is( Crypt::Cipher::min_keysize('DES_EDE'), 24, 'Cipher->min_keysize'); | |
28 | is( Crypt::Cipher::min_keysize('DES_EDE'), 16, 'Cipher->min_keysize'); | |
29 | 29 | is( Crypt::Cipher::default_rounds('DES_EDE'), 16, 'Cipher->default_rounds'); |
30 | 30 | |
31 | 31 | is( Crypt::Cipher->blocksize('DES_EDE'), 8, 'Cipher->blocksize'); |
32 | 32 | is( Crypt::Cipher->keysize('DES_EDE'), 24, 'Cipher->keysize'); |
33 | 33 | is( Crypt::Cipher->max_keysize('DES_EDE'), 24, 'Cipher->max_keysize'); |
34 | is( Crypt::Cipher->min_keysize('DES_EDE'), 24, 'Cipher->min_keysize'); | |
34 | is( Crypt::Cipher->min_keysize('DES_EDE'), 16, 'Cipher->min_keysize'); | |
35 | 35 | is( Crypt::Cipher->default_rounds('DES_EDE'), 16, 'Cipher->default_rounds'); |
36 | 36 | |
37 | 37 | is( Crypt::Cipher::DES_EDE->new($min_key)->blocksize, 8, 'DES_EDE->new()->blocksize'); |
38 | 38 | is( Crypt::Cipher::DES_EDE->new($min_key)->keysize, 24, 'DES_EDE->new()->keysize'); |
39 | 39 | is( Crypt::Cipher::DES_EDE->new($min_key)->max_keysize, 24, 'DES_EDE->new()->max_keysize'); |
40 | is( Crypt::Cipher::DES_EDE->new($min_key)->min_keysize, 24, 'DES_EDE->new()->min_keysize'); | |
40 | is( Crypt::Cipher::DES_EDE->new($min_key)->min_keysize, 16, 'DES_EDE->new()->min_keysize'); | |
41 | 41 | is( Crypt::Cipher::DES_EDE->new($min_key)->default_rounds, 16, 'DES_EDE->new()->default_rounds'); |
42 | 42 | |
43 | 43 | is( Crypt::Cipher->new('DES_EDE', $min_key)->blocksize, 8, 'Cipher->new()->blocksize'); |
44 | 44 | is( Crypt::Cipher->new('DES_EDE', $min_key)->keysize, 24, 'Cipher->new()->keysize'); |
45 | 45 | is( Crypt::Cipher->new('DES_EDE', $min_key)->max_keysize, 24, 'Cipher->new()->max_keysize'); |
46 | is( Crypt::Cipher->new('DES_EDE', $min_key)->min_keysize, 24, 'Cipher->new()->min_keysize'); | |
46 | is( Crypt::Cipher->new('DES_EDE', $min_key)->min_keysize, 16, 'Cipher->new()->min_keysize'); | |
47 | 47 | is( Crypt::Cipher->new('DES_EDE', $min_key)->default_rounds, 16, 'Cipher->new()->default_rounds'); |
48 | 48 | |
49 | 49 | my $block_plain = 'BBBBBBBB'; |
0 | 0 | use strict; |
1 | 1 | use warnings; |
2 | 2 | |
3 | use Test::More tests => 660; | |
3 | use Test::More tests => 663; | |
4 | 4 | use Crypt::PK::ECC; |
5 | 5 | |
6 | 6 | my $data = [ |
87 | 87 | ok( $ec_pub->verify_message(pack("H*", $h->{ECDSA_SHA1}), 'test-data', 'SHA1'), "$h->{PRI_FILE}/ECDSA_SHA1"); |
88 | 88 | ok( $ec_pub->verify_message(pack("H*", $h->{ECDSA_SHA256}), 'test-data', 'SHA256'), "$h->{PRI_FILE}/ECDSA_SHA256"); |
89 | 89 | } |
90 | ||
91 | ### ecc_set_key bug | |
92 | { | |
93 | my $der = pack("H*", "3081be020101041500c78b055db0706fd86b5a15e14b9e51f0043d18f9a074307202010130200607". | |
94 | "2a8648ce3d0101021500fffffffffffffffffffffffffffffffeffffac7330060401000401070429". | |
95 | "043b4c382ce37aa192a4019e763036f4f5dd4d7ebb938cf935318fdced6bc28286531733c3f03c4f". | |
96 | "ee02150100000000000000000001b8fa16dfab9aca16b6b3020101a12c032a00040ca9f03d79907c". | |
97 | "97538177a3027970abefa351073a73120e1b5d2dab02dde37c118a44f8cb267b56"); | |
98 | my $pk = Crypt::PK::ECC->new(\$der); | |
99 | ok($pk->is_private, "ecc_set_key bug"); | |
100 | } | |
101 | ||
102 | ### der_length_custom_type bug: | |
103 | { | |
104 | my $der = pack("H*", "3081a8020101040e20df177a6f7e4bb9fecbd2d75b57a07f307d020101301a06072a8648ce3d0101". | |
105 | "020f00db7c2abf62e35e668076bead208b3037040edb7c2abf62e35e668076bead2088040e659ef8". | |
106 | "ba043916eede8911702b2203150000f50b028e4d696e676875615175290472783fb1040f02094872". | |
107 | "39995a5ee76b55f9c2f098020f00db7c2abf62e35e7628dfac6561c5020101a11203100003a63510". | |
108 | "5c5717812580408a3fd5ac"); | |
109 | my $pk = Crypt::PK::ECC->new(\$der); | |
110 | ok($pk->is_private, "der_length_custom_type bug"); | |
111 | } | |
112 | ||
113 | ### ecc_import_pkcs8 bug | |
114 | { | |
115 | my $der = pack("H*", "308193020100301306072a8648ce3d020106082a8648ce3d030107047930770201010420052f2b26". | |
116 | "1d38522126f6a49cbdb958d5af85ed2c9e8cfebff85c44f20fe89a0fa00a06082a8648ce3d030107". | |
117 | "a144034200043998011b129539269423f531808ed0854bef5b93d00aad8438742c1d272c24ca8649". | |
118 | "e07f17da47c07453183fe35b68d069b700c38cc61dd5d98eb92dc474b573"); | |
119 | my $pk = Crypt::PK::ECC->new(\$der); | |
120 | ok($pk->is_private, "ecc_import_pkcs8 bug"); | |
121 | } |