added libtomcrypt-1.13
This commit is contained in:
parent
2945dea3e2
commit
1eed98f629
2
Doxyfile
2
Doxyfile
@ -23,7 +23,7 @@ PROJECT_NAME = LibTomCrypt
|
||||
# This could be handy for archiving the generated documentation or
|
||||
# if some version control system is used.
|
||||
|
||||
PROJECT_NUMBER = 1.12
|
||||
PROJECT_NUMBER = 1.13
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
|
||||
# base path where the generated documentation will be put.
|
||||
|
6
TODO
6
TODO
@ -1,6 +1,2 @@
|
||||
- document new math function count_lsb_bits
|
||||
- add BOOLEAN type to the ASN world
|
||||
|
||||
- ECC fixed point accelerator
|
||||
- look into X9.63 support [in addition to the LTC style ecc_encrypt_key() not replacing]
|
||||
- long term, start moving macros like CTR over to LTC_CTR to make LTC a bit more "drop-in-able".
|
||||
|
||||
|
15
changes
15
changes
@ -1,3 +1,14 @@
|
||||
June 17th, 2005
|
||||
v1.13 -- Fixed to fortuna_start() to clean up state if an error occurs. Not really useful at this stage (sha256 can't fail) but useful
|
||||
if I ever make fortuna pluggable
|
||||
-- Mike Marin submitted a whole bunch of patches for fixing up the libs on traditional UNIX platforms. Go AIX! Thanks!
|
||||
-- One of bugs found in the multi demo highlights that at least with gcc you need to pass integers with a UL prefix to ensure
|
||||
they're unsigned long
|
||||
-- Updated the FP ECC code to use affine points. It's teh fast.
|
||||
-- Made it so many functions which return CRYPT_BUFFER_OVERFLOW now also indicate the required buffer size, note that not all functions
|
||||
do this (most do though).
|
||||
-- Added F8 chaining mode. It's super neato.
|
||||
|
||||
May 29th, 2006
|
||||
v1.12 -- Fixed OID encoder/decoder/length to properly handle the first two parts of an OID, matches 2002 X.690 now.
|
||||
-- [Wesley Shields] Allows both GMP/LTM and TFM to be defined now.
|
||||
@ -1453,6 +1464,6 @@ v0.02 -- Changed RC5 to only allow 12 to 24 rounds
|
||||
v0.01 -- We will call this the first version.
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/changes,v $ */
|
||||
/* $Revision: 1.206 $ */
|
||||
/* $Date: 2006/05/29 11:21:25 $ */
|
||||
/* $Revision: 1.213 $ */
|
||||
/* $Date: 2006/06/18 01:42:59 $ */
|
||||
|
||||
|
20
crypt.tex
20
crypt.tex
@ -47,7 +47,7 @@
|
||||
\def\gap{\vspace{0.5ex}}
|
||||
\makeindex
|
||||
\begin{document}
|
||||
\title{LibTomCrypt \\ Version 1.12}
|
||||
\title{LibTomCrypt \\ Version 1.13}
|
||||
\author{Tom St Denis \\
|
||||
\\
|
||||
tomstdenis@gmail.com \\
|
||||
@ -280,8 +280,7 @@ There are 32 and 64-bit cyclic rotations as well:
|
||||
|
||||
\section{Functions with Variable Length Output}
|
||||
Certain functions such as (for example) ``rsa\_export()'' give an output that is variable length. To prevent buffer overflows you
|
||||
must pass it the length of the buffer\footnote{Extensive error checking is not in place but it will be in future releases so it is a good idea to follow through with these guidelines.} where
|
||||
the output will be stored. For example:
|
||||
must pass it the length of the buffer where the output will be stored. For example:
|
||||
\begin{small}
|
||||
\begin{verbatim}
|
||||
#include <tomcrypt.h>
|
||||
@ -313,6 +312,9 @@ In the above example if the size of the RSA public key was more than 1024 bytes
|
||||
indicating a buffer overflow would have occurred. If the function succeeds it stores the length of the output
|
||||
back into ``x'' so that the calling application will know how many bytes were used.
|
||||
|
||||
As of v1.13, most functions will update your length on failure to indicate the size required by the function. Not all functions
|
||||
support this so please check the source before you rely on it doing that.
|
||||
|
||||
\section{Functions that need a PRNG}
|
||||
\index{Pseudo Random Number Generator} \index{PRNG}
|
||||
Certain functions such as ``rsa\_make\_key()'' require a Pseudo Random Number Generator (PRNG). These functions do not setup
|
||||
@ -5018,6 +5020,14 @@ typedef struct {
|
||||
*/
|
||||
int (*mulmod)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/** Modular squaring
|
||||
@param a The first source
|
||||
@param b The modulus
|
||||
@param c The destination (a*a mod b)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*sqrmod)(void *a, void *b, void *c);
|
||||
|
||||
/** Modular inversion
|
||||
@param a The value to invert
|
||||
@param b The modulus
|
||||
@ -5231,5 +5241,5 @@ Since the function is given the entire RSA key (for private keys only) CRT is po
|
||||
\end{document}
|
||||
|
||||
% $Source: /cvs/libtom/libtomcrypt/crypt.tex,v $
|
||||
% $Revision: 1.71 $
|
||||
% $Date: 2006/05/29 11:19:08 $
|
||||
% $Revision: 1.74 $
|
||||
% $Date: 2006/06/18 01:35:41 $
|
||||
|
@ -13,21 +13,21 @@ int main(void)
|
||||
|
||||
/* HASH testing */
|
||||
len = sizeof(buf[0]);
|
||||
hash_memory(find_hash("sha256"), "hello", 5, buf[0], &len);
|
||||
hash_memory(find_hash("sha256"), (unsigned char*)"hello", 5, buf[0], &len);
|
||||
len2 = sizeof(buf[0]);
|
||||
hash_memory_multi(find_hash("sha256"), buf[1], &len2, "hello", 5, NULL);
|
||||
hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"hello", 5, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
len2 = sizeof(buf[0]);
|
||||
hash_memory_multi(find_hash("sha256"), buf[1], &len2, "he", 2, "llo", 3, NULL);
|
||||
hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL, 0);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
len2 = sizeof(buf[0]);
|
||||
hash_memory_multi(find_hash("sha256"), buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL);
|
||||
hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
@ -35,21 +35,21 @@ int main(void)
|
||||
|
||||
/* HMAC */
|
||||
len = sizeof(buf[0]);
|
||||
hmac_memory(find_hash("sha256"), key, 16, "hello", 5, buf[0], &len);
|
||||
hmac_memory(find_hash("sha256"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
|
||||
len2 = sizeof(buf[0]);
|
||||
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "hello", 5, NULL);
|
||||
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
len2 = sizeof(buf[0]);
|
||||
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
|
||||
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
len2 = sizeof(buf[0]);
|
||||
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL);
|
||||
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
@ -57,21 +57,21 @@ int main(void)
|
||||
|
||||
/* OMAC */
|
||||
len = sizeof(buf[0]);
|
||||
omac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len);
|
||||
omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
|
||||
len2 = sizeof(buf[0]);
|
||||
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL);
|
||||
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
len2 = sizeof(buf[0]);
|
||||
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
|
||||
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
len2 = sizeof(buf[0]);
|
||||
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL);
|
||||
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
@ -79,21 +79,21 @@ int main(void)
|
||||
|
||||
/* PMAC */
|
||||
len = sizeof(buf[0]);
|
||||
pmac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len);
|
||||
pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
|
||||
len2 = sizeof(buf[0]);
|
||||
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL);
|
||||
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
len2 = sizeof(buf[0]);
|
||||
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
|
||||
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
len2 = sizeof(buf[0]);
|
||||
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL);
|
||||
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
|
||||
if (len != len2 || memcmp(buf[0], buf[1], len)) {
|
||||
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// small demo app that just includes a cipher/hash/prng
|
||||
/* small demo app that just includes a cipher/hash/prng */
|
||||
#include <tomcrypt.h>
|
||||
|
||||
int main(void)
|
||||
|
@ -16,6 +16,13 @@ reg_algs();
|
||||
extern ltc_math_descriptor EXT_MATH_LIB;
|
||||
ltc_mp = EXT_MATH_LIB;
|
||||
#endif
|
||||
time_cipher();
|
||||
time_hash();
|
||||
time_encmacs();
|
||||
time_rsa();
|
||||
time_ecc();
|
||||
time_ecc();
|
||||
return 0;
|
||||
time_keysched();
|
||||
time_cipher();
|
||||
time_cipher2();
|
||||
|
@ -685,9 +685,9 @@ void ecc_gen(void)
|
||||
|
||||
while (mp_cmp(k, order) == LTC_MP_LT) {
|
||||
ltc_mp.ecc_ptmul(k, G, R, modulus, 1);
|
||||
mp_tohex(k, str); fprintf(out, "%s, ", str);
|
||||
mp_tohex(R->x, str); fprintf(out, "%s, ", str);
|
||||
mp_tohex(R->y, str); fprintf(out, "%s\n", str);
|
||||
mp_tohex(k, (char*)str); fprintf(out, "%s, ", (char*)str);
|
||||
mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str);
|
||||
mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str);
|
||||
mp_mul_d(k, 3, k);
|
||||
}
|
||||
}
|
||||
|
BIN
doc/crypt.pdf
BIN
doc/crypt.pdf
Binary file not shown.
31
makefile
31
makefile
@ -4,7 +4,7 @@
|
||||
# Modified by Clay Culver
|
||||
|
||||
# The version
|
||||
VERSION=1.12
|
||||
VERSION=1.13
|
||||
|
||||
# Compiler and Linker Names
|
||||
#CC=gcc
|
||||
@ -150,18 +150,19 @@ src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \
|
||||
src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \
|
||||
src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o \
|
||||
src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \
|
||||
src/modes/ecb/ecb_start.o src/modes/lrw/lrw_decrypt.o src/modes/lrw/lrw_done.o \
|
||||
src/modes/lrw/lrw_encrypt.o src/modes/lrw/lrw_getiv.o src/modes/lrw/lrw_process.o \
|
||||
src/modes/lrw/lrw_setiv.o src/modes/lrw/lrw_start.o src/modes/lrw/lrw_test.o \
|
||||
src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o src/modes/ofb/ofb_encrypt.o \
|
||||
src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o src/modes/ofb/ofb_start.o \
|
||||
src/pk/asn1/der/bit/der_decode_bit_string.o src/pk/asn1/der/bit/der_encode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_length_bit_string.o src/pk/asn1/der/boolean/der_decode_boolean.o \
|
||||
src/pk/asn1/der/boolean/der_encode_boolean.o src/pk/asn1/der/boolean/der_length_boolean.o \
|
||||
src/pk/asn1/der/choice/der_decode_choice.o src/pk/asn1/der/ia5/der_decode_ia5_string.o \
|
||||
src/pk/asn1/der/ia5/der_encode_ia5_string.o src/pk/asn1/der/ia5/der_length_ia5_string.o \
|
||||
src/pk/asn1/der/integer/der_decode_integer.o src/pk/asn1/der/integer/der_encode_integer.o \
|
||||
src/pk/asn1/der/integer/der_length_integer.o \
|
||||
src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \
|
||||
src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \
|
||||
src/modes/lrw/lrw_decrypt.o src/modes/lrw/lrw_done.o src/modes/lrw/lrw_encrypt.o \
|
||||
src/modes/lrw/lrw_getiv.o src/modes/lrw/lrw_process.o src/modes/lrw/lrw_setiv.o \
|
||||
src/modes/lrw/lrw_start.o src/modes/lrw/lrw_test.o src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o \
|
||||
src/modes/ofb/ofb_encrypt.o src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o \
|
||||
src/modes/ofb/ofb_start.o src/pk/asn1/der/bit/der_decode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_encode_bit_string.o src/pk/asn1/der/bit/der_length_bit_string.o \
|
||||
src/pk/asn1/der/boolean/der_decode_boolean.o src/pk/asn1/der/boolean/der_encode_boolean.o \
|
||||
src/pk/asn1/der/boolean/der_length_boolean.o src/pk/asn1/der/choice/der_decode_choice.o \
|
||||
src/pk/asn1/der/ia5/der_decode_ia5_string.o src/pk/asn1/der/ia5/der_encode_ia5_string.o \
|
||||
src/pk/asn1/der/ia5/der_length_ia5_string.o src/pk/asn1/der/integer/der_decode_integer.o \
|
||||
src/pk/asn1/der/integer/der_encode_integer.o src/pk/asn1/der/integer/der_length_integer.o \
|
||||
src/pk/asn1/der/object_identifier/der_decode_object_identifier.o \
|
||||
src/pk/asn1/der/object_identifier/der_encode_object_identifier.o \
|
||||
src/pk/asn1/der/object_identifier/der_length_object_identifier.o \
|
||||
@ -366,5 +367,5 @@ zipup: no_oops docs
|
||||
|
||||
|
||||
# $Source: /cvs/libtom/libtomcrypt/makefile,v $
|
||||
# $Revision: 1.123 $
|
||||
# $Date: 2006/05/25 10:33:01 $
|
||||
# $Revision: 1.126 $
|
||||
# $Date: 2006/06/16 23:52:08 $
|
||||
|
29
makefile.icc
29
makefile.icc
@ -142,18 +142,19 @@ src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \
|
||||
src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \
|
||||
src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o \
|
||||
src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \
|
||||
src/modes/ecb/ecb_start.o src/modes/lrw/lrw_decrypt.o src/modes/lrw/lrw_done.o \
|
||||
src/modes/lrw/lrw_encrypt.o src/modes/lrw/lrw_getiv.o src/modes/lrw/lrw_process.o \
|
||||
src/modes/lrw/lrw_setiv.o src/modes/lrw/lrw_start.o src/modes/lrw/lrw_test.o \
|
||||
src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o src/modes/ofb/ofb_encrypt.o \
|
||||
src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o src/modes/ofb/ofb_start.o \
|
||||
src/pk/asn1/der/bit/der_decode_bit_string.o src/pk/asn1/der/bit/der_encode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_length_bit_string.o src/pk/asn1/der/boolean/der_decode_boolean.o \
|
||||
src/pk/asn1/der/boolean/der_encode_boolean.o src/pk/asn1/der/boolean/der_length_boolean.o \
|
||||
src/pk/asn1/der/choice/der_decode_choice.o src/pk/asn1/der/ia5/der_decode_ia5_string.o \
|
||||
src/pk/asn1/der/ia5/der_encode_ia5_string.o src/pk/asn1/der/ia5/der_length_ia5_string.o \
|
||||
src/pk/asn1/der/integer/der_decode_integer.o src/pk/asn1/der/integer/der_encode_integer.o \
|
||||
src/pk/asn1/der/integer/der_length_integer.o \
|
||||
src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \
|
||||
src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \
|
||||
src/modes/lrw/lrw_decrypt.o src/modes/lrw/lrw_done.o src/modes/lrw/lrw_encrypt.o \
|
||||
src/modes/lrw/lrw_getiv.o src/modes/lrw/lrw_process.o src/modes/lrw/lrw_setiv.o \
|
||||
src/modes/lrw/lrw_start.o src/modes/lrw/lrw_test.o src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o \
|
||||
src/modes/ofb/ofb_encrypt.o src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o \
|
||||
src/modes/ofb/ofb_start.o src/pk/asn1/der/bit/der_decode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_encode_bit_string.o src/pk/asn1/der/bit/der_length_bit_string.o \
|
||||
src/pk/asn1/der/boolean/der_decode_boolean.o src/pk/asn1/der/boolean/der_encode_boolean.o \
|
||||
src/pk/asn1/der/boolean/der_length_boolean.o src/pk/asn1/der/choice/der_decode_choice.o \
|
||||
src/pk/asn1/der/ia5/der_decode_ia5_string.o src/pk/asn1/der/ia5/der_encode_ia5_string.o \
|
||||
src/pk/asn1/der/ia5/der_length_ia5_string.o src/pk/asn1/der/integer/der_decode_integer.o \
|
||||
src/pk/asn1/der/integer/der_encode_integer.o src/pk/asn1/der/integer/der_length_integer.o \
|
||||
src/pk/asn1/der/object_identifier/der_decode_object_identifier.o \
|
||||
src/pk/asn1/der/object_identifier/der_encode_object_identifier.o \
|
||||
src/pk/asn1/der/object_identifier/der_length_object_identifier.o \
|
||||
@ -276,6 +277,6 @@ install: library
|
||||
install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
|
||||
|
||||
# $Source: /cvs/libtom/libtomcrypt/makefile.icc,v $
|
||||
# $Revision: 1.56 $
|
||||
# $Date: 2006/05/25 10:33:01 $
|
||||
# $Revision: 1.58 $
|
||||
# $Date: 2006/06/16 23:52:08 $
|
||||
|
||||
|
@ -52,18 +52,19 @@ src/modes/cfb/cfb_getiv.obj src/modes/cfb/cfb_setiv.obj src/modes/cfb/cfb_start.
|
||||
src/modes/ctr/ctr_decrypt.obj src/modes/ctr/ctr_done.obj src/modes/ctr/ctr_encrypt.obj \
|
||||
src/modes/ctr/ctr_getiv.obj src/modes/ctr/ctr_setiv.obj src/modes/ctr/ctr_start.obj \
|
||||
src/modes/ecb/ecb_decrypt.obj src/modes/ecb/ecb_done.obj src/modes/ecb/ecb_encrypt.obj \
|
||||
src/modes/ecb/ecb_start.obj src/modes/lrw/lrw_decrypt.obj src/modes/lrw/lrw_done.obj \
|
||||
src/modes/lrw/lrw_encrypt.obj src/modes/lrw/lrw_getiv.obj src/modes/lrw/lrw_process.obj \
|
||||
src/modes/lrw/lrw_setiv.obj src/modes/lrw/lrw_start.obj src/modes/lrw/lrw_test.obj \
|
||||
src/modes/ofb/ofb_decrypt.obj src/modes/ofb/ofb_done.obj src/modes/ofb/ofb_encrypt.obj \
|
||||
src/modes/ofb/ofb_getiv.obj src/modes/ofb/ofb_setiv.obj src/modes/ofb/ofb_start.obj \
|
||||
src/pk/asn1/der/bit/der_decode_bit_string.obj src/pk/asn1/der/bit/der_encode_bit_string.obj \
|
||||
src/pk/asn1/der/bit/der_length_bit_string.obj src/pk/asn1/der/boolean/der_decode_boolean.obj \
|
||||
src/pk/asn1/der/boolean/der_encode_boolean.obj src/pk/asn1/der/boolean/der_length_boolean.obj \
|
||||
src/pk/asn1/der/choice/der_decode_choice.obj src/pk/asn1/der/ia5/der_decode_ia5_string.obj \
|
||||
src/pk/asn1/der/ia5/der_encode_ia5_string.obj src/pk/asn1/der/ia5/der_length_ia5_string.obj \
|
||||
src/pk/asn1/der/integer/der_decode_integer.obj src/pk/asn1/der/integer/der_encode_integer.obj \
|
||||
src/pk/asn1/der/integer/der_length_integer.obj \
|
||||
src/modes/ecb/ecb_start.obj src/modes/f8/f8_decrypt.obj src/modes/f8/f8_done.obj src/modes/f8/f8_encrypt.obj \
|
||||
src/modes/f8/f8_getiv.obj src/modes/f8/f8_setiv.obj src/modes/f8/f8_start.obj src/modes/f8/f8_test_mode.obj \
|
||||
src/modes/lrw/lrw_decrypt.obj src/modes/lrw/lrw_done.obj src/modes/lrw/lrw_encrypt.obj \
|
||||
src/modes/lrw/lrw_getiv.obj src/modes/lrw/lrw_process.obj src/modes/lrw/lrw_setiv.obj \
|
||||
src/modes/lrw/lrw_start.obj src/modes/lrw/lrw_test.obj src/modes/ofb/ofb_decrypt.obj src/modes/ofb/ofb_done.obj \
|
||||
src/modes/ofb/ofb_encrypt.obj src/modes/ofb/ofb_getiv.obj src/modes/ofb/ofb_setiv.obj \
|
||||
src/modes/ofb/ofb_start.obj src/pk/asn1/der/bit/der_decode_bit_string.obj \
|
||||
src/pk/asn1/der/bit/der_encode_bit_string.obj src/pk/asn1/der/bit/der_length_bit_string.obj \
|
||||
src/pk/asn1/der/boolean/der_decode_boolean.obj src/pk/asn1/der/boolean/der_encode_boolean.obj \
|
||||
src/pk/asn1/der/boolean/der_length_boolean.obj src/pk/asn1/der/choice/der_decode_choice.obj \
|
||||
src/pk/asn1/der/ia5/der_decode_ia5_string.obj src/pk/asn1/der/ia5/der_encode_ia5_string.obj \
|
||||
src/pk/asn1/der/ia5/der_length_ia5_string.obj src/pk/asn1/der/integer/der_decode_integer.obj \
|
||||
src/pk/asn1/der/integer/der_encode_integer.obj src/pk/asn1/der/integer/der_length_integer.obj \
|
||||
src/pk/asn1/der/object_identifier/der_decode_object_identifier.obj \
|
||||
src/pk/asn1/der/object_identifier/der_encode_object_identifier.obj \
|
||||
src/pk/asn1/der/object_identifier/der_length_object_identifier.obj \
|
||||
@ -134,5 +135,5 @@ timing: demos/timing.c library
|
||||
cl $(CFLAGS) demos/timing.c testprof/tomcrypt_prof.lib tomcrypt.lib advapi32.lib $(EXTRALIBS)
|
||||
|
||||
# $Source: /cvs/libtom/libtomcrypt/makefile.msvc,v $
|
||||
# $Revision: 1.34 $
|
||||
# $Date: 2006/05/25 10:33:01 $
|
||||
# $Revision: 1.36 $
|
||||
# $Date: 2006/06/16 23:52:08 $
|
||||
|
@ -6,7 +6,7 @@
|
||||
# Tom St Denis
|
||||
|
||||
# The version
|
||||
VERSION=0:112
|
||||
VERSION=0:113
|
||||
|
||||
# Compiler and Linker Names
|
||||
CC=libtool --mode=compile --tag=CC gcc
|
||||
@ -147,18 +147,19 @@ src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \
|
||||
src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \
|
||||
src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o \
|
||||
src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \
|
||||
src/modes/ecb/ecb_start.o src/modes/lrw/lrw_decrypt.o src/modes/lrw/lrw_done.o \
|
||||
src/modes/lrw/lrw_encrypt.o src/modes/lrw/lrw_getiv.o src/modes/lrw/lrw_process.o \
|
||||
src/modes/lrw/lrw_setiv.o src/modes/lrw/lrw_start.o src/modes/lrw/lrw_test.o \
|
||||
src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o src/modes/ofb/ofb_encrypt.o \
|
||||
src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o src/modes/ofb/ofb_start.o \
|
||||
src/pk/asn1/der/bit/der_decode_bit_string.o src/pk/asn1/der/bit/der_encode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_length_bit_string.o src/pk/asn1/der/boolean/der_decode_boolean.o \
|
||||
src/pk/asn1/der/boolean/der_encode_boolean.o src/pk/asn1/der/boolean/der_length_boolean.o \
|
||||
src/pk/asn1/der/choice/der_decode_choice.o src/pk/asn1/der/ia5/der_decode_ia5_string.o \
|
||||
src/pk/asn1/der/ia5/der_encode_ia5_string.o src/pk/asn1/der/ia5/der_length_ia5_string.o \
|
||||
src/pk/asn1/der/integer/der_decode_integer.o src/pk/asn1/der/integer/der_encode_integer.o \
|
||||
src/pk/asn1/der/integer/der_length_integer.o \
|
||||
src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \
|
||||
src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \
|
||||
src/modes/lrw/lrw_decrypt.o src/modes/lrw/lrw_done.o src/modes/lrw/lrw_encrypt.o \
|
||||
src/modes/lrw/lrw_getiv.o src/modes/lrw/lrw_process.o src/modes/lrw/lrw_setiv.o \
|
||||
src/modes/lrw/lrw_start.o src/modes/lrw/lrw_test.o src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o \
|
||||
src/modes/ofb/ofb_encrypt.o src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o \
|
||||
src/modes/ofb/ofb_start.o src/pk/asn1/der/bit/der_decode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_encode_bit_string.o src/pk/asn1/der/bit/der_length_bit_string.o \
|
||||
src/pk/asn1/der/boolean/der_decode_boolean.o src/pk/asn1/der/boolean/der_encode_boolean.o \
|
||||
src/pk/asn1/der/boolean/der_length_boolean.o src/pk/asn1/der/choice/der_decode_choice.o \
|
||||
src/pk/asn1/der/ia5/der_decode_ia5_string.o src/pk/asn1/der/ia5/der_encode_ia5_string.o \
|
||||
src/pk/asn1/der/ia5/der_length_ia5_string.o src/pk/asn1/der/integer/der_decode_integer.o \
|
||||
src/pk/asn1/der/integer/der_encode_integer.o src/pk/asn1/der/integer/der_length_integer.o \
|
||||
src/pk/asn1/der/object_identifier/der_decode_object_identifier.o \
|
||||
src/pk/asn1/der/object_identifier/der_encode_object_identifier.o \
|
||||
src/pk/asn1/der/object_identifier/der_length_object_identifier.o \
|
||||
@ -264,5 +265,5 @@ timing: library testprof/$(LIBTEST) $(TIMINGS)
|
||||
gcc -o $(TIMING) $(TIMINGS) -ltomcrypt_prof -ltomcrypt $(EXTRALIBS)
|
||||
|
||||
# $Source: /cvs/libtom/libtomcrypt/makefile.shared,v $
|
||||
# $Revision: 1.55 $
|
||||
# $Date: 2006/05/25 10:33:01 $
|
||||
# $Revision: 1.58 $
|
||||
# $Date: 2006/06/16 23:52:08 $
|
||||
|
@ -42,6 +42,7 @@ int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outle
|
||||
}
|
||||
|
||||
if (*outlen < hash_descriptor[hash].hashsize) {
|
||||
*outlen = hash_descriptor[hash].hashsize;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
if ((err = hash_descriptor[hash].init(&md)) != CRYPT_OK) {
|
||||
|
@ -38,6 +38,7 @@ int hash_memory(int hash, const unsigned char *in, unsigned long inlen, unsigned
|
||||
}
|
||||
|
||||
if (*outlen < hash_descriptor[hash].hashsize) {
|
||||
*outlen = hash_descriptor[hash].hashsize;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
|
||||
}
|
||||
|
||||
if (*outlen < hash_descriptor[hash].hashsize) {
|
||||
*outlen = hash_descriptor[hash].hashsize;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* version */
|
||||
#define CRYPT 0x0112
|
||||
#define SCRYPT "1.12"
|
||||
#define CRYPT 0x0113
|
||||
#define SCRYPT "1.13"
|
||||
|
||||
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
|
||||
#define MAXBLOCKSIZE 128
|
||||
|
@ -7,19 +7,28 @@
|
||||
/* this is the default LibTomCrypt macro */
|
||||
void crypt_argchk(char *v, char *s, int d);
|
||||
#define LTC_ARGCHK(x) if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); }
|
||||
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
||||
|
||||
#elif ARGTYPE == 1
|
||||
|
||||
/* fatal type of error */
|
||||
#define LTC_ARGCHK(x) assert((x))
|
||||
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
||||
|
||||
#elif ARGTYPE == 2
|
||||
|
||||
#define LTC_ARGCHK(x) if (!(x)) { fprintf(stderr, "\nwarning: ARGCHK failed at %s:%d\n", __FILE__, __LINE__); }
|
||||
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
||||
|
||||
#elif ARGTYPE == 3
|
||||
|
||||
#define LTC_ARGCHK(x)
|
||||
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
||||
|
||||
#elif ARGTYPE == 4
|
||||
|
||||
#define LTC_ARGCHK(x) return CRYPT_INVALID_ARG;
|
||||
#define LTC_ARGCHKVD(x) return;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -274,6 +274,24 @@ typedef struct {
|
||||
} symmetric_LRW;
|
||||
#endif
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
/** A block cipher F8 structure */
|
||||
typedef struct {
|
||||
/** The index of the cipher chosen */
|
||||
int cipher,
|
||||
/** The block size of the given cipher */
|
||||
blocklen,
|
||||
/** The padding offset */
|
||||
padlen;
|
||||
/** The current IV */
|
||||
unsigned char IV[MAXBLOCKSIZE],
|
||||
MIV[MAXBLOCKSIZE];
|
||||
/** Current block count */
|
||||
ulong32 blockcnt;
|
||||
/** The scheduled key */
|
||||
symmetric_key key;
|
||||
} symmetric_F8;
|
||||
#endif
|
||||
|
||||
|
||||
/** cipher descriptor table, last entry has "name == NULL" to mark the end of table */
|
||||
@ -706,9 +724,21 @@ int lrw_test(void);
|
||||
|
||||
/* don't call */
|
||||
int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
int f8_start( int cipher, const unsigned char *IV,
|
||||
const unsigned char *key, int keylen,
|
||||
const unsigned char *salt_key, int skeylen,
|
||||
int num_rounds, symmetric_F8 *f8);
|
||||
int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);
|
||||
int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8);
|
||||
int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8);
|
||||
int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8);
|
||||
int f8_done(symmetric_F8 *f8);
|
||||
#endif
|
||||
|
||||
|
||||
int find_cipher(const char *name);
|
||||
int find_cipher_any(const char *name, int blocklen, int keylen);
|
||||
int find_cipher_id(unsigned char ID);
|
||||
|
@ -140,6 +140,9 @@
|
||||
#define CBC
|
||||
#define CTR
|
||||
|
||||
/* F8 chaining mode */
|
||||
#define LTC_F8_MODE
|
||||
|
||||
/* LRW mode */
|
||||
#define LRW_MODE
|
||||
#ifndef LTC_NO_TABLES
|
||||
|
@ -225,7 +225,7 @@ typedef struct {
|
||||
@param d The remainder (can be NULL to signify don't care)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*div)(void *a, void *b, void *c, void *d);
|
||||
int (*mpdiv)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/** divide by two
|
||||
@param a The integer to divide (shift right)
|
||||
@ -267,6 +267,14 @@ typedef struct {
|
||||
*/
|
||||
int (*mulmod)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/** Modular squaring
|
||||
@param a The first source
|
||||
@param b The modulus
|
||||
@param c The destination (a*a mod b)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*sqrmod)(void *a, void *b, void *c);
|
||||
|
||||
/** Modular inversion
|
||||
@param a The value to invert
|
||||
@param b The modulus
|
||||
@ -446,14 +454,15 @@ extern const ltc_math_descriptor gmp_desc;
|
||||
#define mp_mul(a, b, c) ltc_mp.mul(a, b, c)
|
||||
#define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c)
|
||||
#define mp_sqr(a, b) ltc_mp.sqr(a, b)
|
||||
#define mp_div(a, b, c, d) ltc_mp.div(a, b, c, d)
|
||||
#define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d)
|
||||
#define mp_div_2(a, b) ltc_mp.div_2(a, b)
|
||||
#define mp_mod(a, b, c) ltc_mp.div(a, b, NULL, c)
|
||||
#define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c)
|
||||
#define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c)
|
||||
#define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c)
|
||||
#define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c)
|
||||
|
||||
#define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d)
|
||||
#define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c)
|
||||
#define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c)
|
||||
|
||||
#define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b)
|
||||
|
@ -359,7 +359,7 @@ typedef struct ltc_asn1_list_ {
|
||||
int LTC_MACRO_temp = (index); \
|
||||
ltc_asn1_list *LTC_MACRO_list = (list); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].type = (Type); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].data = (Data); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].data = (void*)(Data); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].size = (Size); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].used = 0; \
|
||||
} while (0);
|
||||
|
@ -35,11 +35,12 @@
|
||||
/** Our FP cache */
|
||||
static struct {
|
||||
ecc_point *g, /* cached COPY of base point */
|
||||
*LUT[1<<FP_LUT]; /* fixed point lookup */
|
||||
*LUT[1U<<FP_LUT]; /* fixed point lookup */
|
||||
void *mu; /* copy of the montgomery constant */
|
||||
int lru_count; /* amount of times this entry has been used */
|
||||
} fp_cache[FP_ENTRIES];
|
||||
|
||||
LTC_MUTEX_GLOBAL(ltc_ecc_fp_lock);
|
||||
LTC_MUTEX_GLOBAL(ltc_ecc_fp_lock)
|
||||
|
||||
/* simple table to help direct the generation of the LUT */
|
||||
static const struct {
|
||||
@ -574,7 +575,8 @@ static const struct {
|
||||
/* find a hole and free as required */
|
||||
static int find_hole(void)
|
||||
{
|
||||
int x, y, z;
|
||||
unsigned x;
|
||||
int y, z;
|
||||
for (z = 0, y = INT_MAX, x = 0; x < FP_ENTRIES; x++) {
|
||||
if (fp_cache[x].lru_count < y) {
|
||||
z = x;
|
||||
@ -591,9 +593,13 @@ static int find_hole(void)
|
||||
|
||||
/* free entry z */
|
||||
if (fp_cache[z].g) {
|
||||
if (fp_cache[z].mu != NULL) {
|
||||
mp_clear(fp_cache[z].mu);
|
||||
fp_cache[z].mu = NULL;
|
||||
}
|
||||
ltc_ecc_del_point(fp_cache[z].g);
|
||||
fp_cache[z].g = NULL;
|
||||
for (x = 0; x < (1<<FP_LUT); x++) {
|
||||
fp_cache[z].g = NULL;
|
||||
for (x = 0; x < (1U<<FP_LUT); x++) {
|
||||
ltc_ecc_del_point(fp_cache[z].LUT[x]);
|
||||
fp_cache[z].LUT[x] = NULL;
|
||||
}
|
||||
@ -602,6 +608,7 @@ static int find_hole(void)
|
||||
return z;
|
||||
}
|
||||
|
||||
/* determine if a base is already in the cache and if so, where */
|
||||
static int find_base(ecc_point *g)
|
||||
{
|
||||
int x;
|
||||
@ -619,9 +626,10 @@ static int find_base(ecc_point *g)
|
||||
return x;
|
||||
}
|
||||
|
||||
/* add a new base to the cache */
|
||||
static int add_entry(int idx, ecc_point *g)
|
||||
{
|
||||
int x, y;
|
||||
unsigned x, y;
|
||||
|
||||
/* allocate base and LUT */
|
||||
fp_cache[idx].g = ltc_ecc_new_point();
|
||||
@ -638,7 +646,7 @@ static int add_entry(int idx, ecc_point *g)
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
for (x = 0; x < (1<<FP_LUT); x++) {
|
||||
for (x = 0; x < (1U<<FP_LUT); x++) {
|
||||
fp_cache[idx].LUT[x] = ltc_ecc_new_point();
|
||||
if (fp_cache[idx].LUT[x] == NULL) {
|
||||
for (y = 0; y < x; y++) {
|
||||
@ -664,6 +672,9 @@ static int add_entry(int idx, ecc_point *g)
|
||||
static int build_lut(int idx, void *modulus, void *mp, void *mu)
|
||||
{
|
||||
unsigned x, y, err, bitlen, lut_gap;
|
||||
void *tmp;
|
||||
|
||||
tmp = NULL;
|
||||
|
||||
/* sanity check to make sure lut_order table is of correct size, should compile out to a NOP if true */
|
||||
if ((sizeof(lut_orders) / sizeof(lut_orders[0])) < (1U<<FP_LUT)) {
|
||||
@ -679,16 +690,21 @@ static int build_lut(int idx, void *modulus, void *mp, void *mu)
|
||||
}
|
||||
lut_gap = bitlen / FP_LUT;
|
||||
|
||||
/* init the mu */
|
||||
if ((err = mp_init_copy(&fp_cache[idx].mu, mu)) != CRYPT_OK) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
/* copy base */
|
||||
if ((mp_mulmod(fp_cache[idx].g->x, mu, modulus, fp_cache[idx].LUT[1]->x) != CRYPT_OK) ||
|
||||
(mp_mulmod(fp_cache[idx].g->y, mu, modulus, fp_cache[idx].LUT[1]->y) != CRYPT_OK) ||
|
||||
(mp_mulmod(fp_cache[idx].g->z, mu, modulus, fp_cache[idx].LUT[1]->z) != CRYPT_OK)) { goto ERR; }
|
||||
(mp_mulmod(fp_cache[idx].g->z, mu, modulus, fp_cache[idx].LUT[1]->z) != CRYPT_OK)) { goto ERR; }
|
||||
|
||||
/* make all single bit entries */
|
||||
for (x = 1; x < FP_LUT; x++) {
|
||||
if ((mp_copy(fp_cache[idx].LUT[1<<(x-1)]->x, fp_cache[idx].LUT[1<<x]->x) != CRYPT_OK) ||
|
||||
(mp_copy(fp_cache[idx].LUT[1<<(x-1)]->y, fp_cache[idx].LUT[1<<x]->y) != CRYPT_OK) ||
|
||||
(mp_copy(fp_cache[idx].LUT[1<<(x-1)]->z, fp_cache[idx].LUT[1<<x]->z) != CRYPT_OK)) { goto ERR; }
|
||||
(mp_copy(fp_cache[idx].LUT[1<<(x-1)]->z, fp_cache[idx].LUT[1<<x]->z) != CRYPT_OK)) { goto ERR; }
|
||||
|
||||
/* now double it bitlen/FP_LUT times */
|
||||
for (y = 0; y < lut_gap; y++) {
|
||||
@ -700,7 +716,7 @@ static int build_lut(int idx, void *modulus, void *mp, void *mu)
|
||||
|
||||
/* now make all entries in increase order of hamming weight */
|
||||
for (x = 2; x <= FP_LUT; x++) {
|
||||
for (y = 0; y < (1<<FP_LUT); y++) {
|
||||
for (y = 0; y < (1UL<<FP_LUT); y++) {
|
||||
if (lut_orders[y].ham != (int)x) continue;
|
||||
|
||||
/* perform the add */
|
||||
@ -711,20 +727,55 @@ static int build_lut(int idx, void *modulus, void *mp, void *mu)
|
||||
}
|
||||
}
|
||||
|
||||
/* now map all entries back to affine space to make point addition faster */
|
||||
if ((err = mp_init(&tmp)) != CRYPT_OK) { goto ERR; }
|
||||
for (x = 1; x < (1UL<<FP_LUT); x++) {
|
||||
/* convert z to normal from montgomery */
|
||||
if ((err = mp_montgomery_reduce(fp_cache[idx].LUT[x]->z, modulus, mp)) != CRYPT_OK) { goto ERR; }
|
||||
|
||||
/* invert it */
|
||||
if ((err = mp_invmod(fp_cache[idx].LUT[x]->z, modulus, fp_cache[idx].LUT[x]->z)) != CRYPT_OK) { goto ERR; }
|
||||
|
||||
/* now square it */
|
||||
if ((err = mp_sqrmod(fp_cache[idx].LUT[x]->z, modulus, tmp)) != CRYPT_OK) { goto ERR; }
|
||||
|
||||
/* fix x */
|
||||
if ((err = mp_mulmod(fp_cache[idx].LUT[x]->x, tmp, modulus, fp_cache[idx].LUT[x]->x)) != CRYPT_OK) { goto ERR; }
|
||||
|
||||
/* get 1/z^3 */
|
||||
if ((err = mp_mulmod(tmp, fp_cache[idx].LUT[x]->z, modulus, tmp)) != CRYPT_OK) { goto ERR; }
|
||||
|
||||
/* fix y */
|
||||
if ((err = mp_mulmod(fp_cache[idx].LUT[x]->y, tmp, modulus, fp_cache[idx].LUT[x]->y)) != CRYPT_OK) { goto ERR; }
|
||||
|
||||
/* free z */
|
||||
mp_clear(fp_cache[idx].LUT[x]->z);
|
||||
fp_cache[idx].LUT[x]->z = NULL;
|
||||
}
|
||||
mp_clear(tmp);
|
||||
|
||||
return CRYPT_OK;
|
||||
ERR:
|
||||
err = CRYPT_MEM;
|
||||
DONE:
|
||||
for (y = 0; y < (1<<FP_LUT); y++) {
|
||||
for (y = 0; y < (1U<<FP_LUT); y++) {
|
||||
ltc_ecc_del_point(fp_cache[idx].LUT[y]);
|
||||
fp_cache[idx].LUT[y] = NULL;
|
||||
}
|
||||
ltc_ecc_del_point(fp_cache[idx].g);
|
||||
fp_cache[idx].g = NULL;
|
||||
fp_cache[idx].lru_count = 0;
|
||||
return CRYPT_MEM;
|
||||
if (fp_cache[idx].mu != NULL) {
|
||||
mp_clear(fp_cache[idx].mu);
|
||||
fp_cache[idx].mu = NULL;
|
||||
}
|
||||
if (tmp != NULL) {
|
||||
mp_clear(tmp);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
/* perform a fixed point ECC mulmod */
|
||||
static int accel_fp_mul(int idx, void *k, ecc_point *R, void *modulus, void *mp, int map)
|
||||
{
|
||||
unsigned char kb[128];
|
||||
@ -831,7 +882,7 @@ static int accel_fp_mul(int idx, void *k, ecc_point *R, void *modulus, void *mp,
|
||||
} else if (z) {
|
||||
if ((mp_copy(fp_cache[idx].LUT[z]->x, R->x) != CRYPT_OK) ||
|
||||
(mp_copy(fp_cache[idx].LUT[z]->y, R->y) != CRYPT_OK) ||
|
||||
(mp_copy(fp_cache[idx].LUT[z]->z, R->z) != CRYPT_OK)) { return CRYPT_MEM; }
|
||||
(mp_copy(fp_cache[idx].mu, R->z) != CRYPT_OK)) { return CRYPT_MEM; }
|
||||
first = 0;
|
||||
}
|
||||
}
|
||||
@ -846,6 +897,14 @@ static int accel_fp_mul(int idx, void *k, ecc_point *R, void *modulus, void *mp,
|
||||
return err;
|
||||
}
|
||||
|
||||
/** ECC Fixed Point mulmod global
|
||||
@param k The multiplicand
|
||||
@param G Base point to multiply
|
||||
@param R [out] Destination of product
|
||||
@param modulus The modulus for the curve
|
||||
@param map [boolean] If non-zero maps the point back to affine co-ordinates, otherwise it's left in jacobian-montgomery form
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map)
|
||||
{
|
||||
int idx, err;
|
||||
@ -909,18 +968,23 @@ LBL_ERR:
|
||||
return err;
|
||||
}
|
||||
|
||||
/** Free the Fixed Point tables */
|
||||
void ltc_ecc_fp_free(void)
|
||||
{
|
||||
int x, y;
|
||||
unsigned x, y;
|
||||
LTC_MUTEX_LOCK(<c_ecc_fp_lock);
|
||||
for (x = 0; x < FP_ENTRIES; x++) {
|
||||
if (fp_cache[x].g != NULL) {
|
||||
for (y = 0; y < (1<<FP_LUT); y++) {
|
||||
for (y = 0; y < (1U<<FP_LUT); y++) {
|
||||
ltc_ecc_del_point(fp_cache[x].LUT[y]);
|
||||
fp_cache[x].LUT[y] = NULL;
|
||||
}
|
||||
ltc_ecc_del_point(fp_cache[x].g);
|
||||
fp_cache[x].g = NULL;
|
||||
if (fp_cache[x].mu != NULL) {
|
||||
mp_clear(fp_cache[x].mu);
|
||||
fp_cache[x].mu = NULL;
|
||||
}
|
||||
fp_cache[x].lru_count = 0;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ static int init(void **a)
|
||||
|
||||
static void deinit(void *a)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHKVD(a != NULL);
|
||||
mpz_clear(a);
|
||||
XFREE(a);
|
||||
}
|
||||
@ -316,6 +316,16 @@ static int mulmod(void *a, void *b, void *c, void *d)
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int sqrmod(void *a, void *b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(b != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
mpz_mul(c, a, a);
|
||||
mpz_mod(c, c, b);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* invmod */
|
||||
static int invmod(void *a, void *b, void *c)
|
||||
{
|
||||
@ -329,10 +339,9 @@ static int invmod(void *a, void *b, void *c)
|
||||
/* setup */
|
||||
static int montgomery_setup(void *a, void **b)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(b != NULL);
|
||||
*b = 1;
|
||||
*b = (void *)1;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
@ -419,6 +428,7 @@ const ltc_math_descriptor gmp_desc = {
|
||||
&lcm,
|
||||
|
||||
&mulmod,
|
||||
&sqrmod,
|
||||
&invmod,
|
||||
|
||||
&montgomery_setup,
|
||||
|
@ -60,7 +60,7 @@ static int init(void **a)
|
||||
|
||||
static void deinit(void *a)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHKVD(a != NULL);
|
||||
mp_clear(a);
|
||||
XFREE(a);
|
||||
}
|
||||
@ -317,6 +317,14 @@ static int mulmod(void *a, void *b, void *c, void *d)
|
||||
return mpi_to_ltc_error(mp_mulmod(a,b,c,d));
|
||||
}
|
||||
|
||||
static int sqrmod(void *a, void *b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(b != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
return mpi_to_ltc_error(mp_sqrmod(a,b,c));
|
||||
}
|
||||
|
||||
/* invmod */
|
||||
static int invmod(void *a, void *b, void *c)
|
||||
{
|
||||
@ -426,6 +434,7 @@ const ltc_math_descriptor ltm_desc = {
|
||||
&lcm,
|
||||
|
||||
&mulmod,
|
||||
&sqrmod,
|
||||
&invmod,
|
||||
|
||||
&montgomery_setup,
|
||||
|
@ -55,7 +55,7 @@ static int init(void **a)
|
||||
|
||||
static void deinit(void *a)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHKVD(a != NULL);
|
||||
XFREE(a);
|
||||
}
|
||||
|
||||
@ -328,6 +328,14 @@ static int mulmod(void *a, void *b, void *c, void *d)
|
||||
return tfm_to_ltc_error(fp_mulmod(a,b,c,d));
|
||||
}
|
||||
|
||||
static int sqrmod(void *a, void *b, void *c)
|
||||
{
|
||||
LTC_ARGCHK(a != NULL);
|
||||
LTC_ARGCHK(b != NULL);
|
||||
LTC_ARGCHK(c != NULL);
|
||||
return tfm_to_ltc_error(fp_sqrmod(a,b,c));
|
||||
}
|
||||
|
||||
/* invmod */
|
||||
static int invmod(void *a, void *b, void *c)
|
||||
{
|
||||
@ -536,7 +544,7 @@ static int tfm_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R
|
||||
/* should we dbl instead? */
|
||||
fp_sub(modulus, Q->y, &t1);
|
||||
if ( (fp_cmp(P->x, Q->x) == FP_EQ) &&
|
||||
(fp_cmp(P->z, Q->z) == FP_EQ) &&
|
||||
(Q->z != NULL && fp_cmp(P->z, Q->z) == FP_EQ) &&
|
||||
(fp_cmp(P->y, Q->y) == FP_EQ || fp_cmp(P->y, &t1) == FP_EQ)) {
|
||||
return tfm_ecc_projective_dbl_point(P, R, modulus, Mp);
|
||||
}
|
||||
@ -546,6 +554,7 @@ static int tfm_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R
|
||||
fp_copy(P->z, &z);
|
||||
|
||||
/* if Z is one then these are no-operations */
|
||||
if (Q->z != NULL) {
|
||||
/* T1 = Z' * Z' */
|
||||
fp_sqr(Q->z, &t1);
|
||||
fp_montgomery_reduce(&t1, modulus, mp);
|
||||
@ -558,6 +567,7 @@ static int tfm_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R
|
||||
/* Y = Y * T1 */
|
||||
fp_mul(&t1, &y, &y);
|
||||
fp_montgomery_reduce(&y, modulus, mp);
|
||||
}
|
||||
|
||||
/* T1 = Z*Z */
|
||||
fp_sqr(&z, &t1);
|
||||
@ -604,9 +614,11 @@ static int tfm_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R
|
||||
}
|
||||
|
||||
/* if Z' != 1 */
|
||||
if (Q->z != NULL) {
|
||||
/* Z = Z * Z' */
|
||||
fp_mul(&z, Q->z, &z);
|
||||
fp_montgomery_reduce(&z, modulus, mp);
|
||||
}
|
||||
|
||||
/* Z = Z * X */
|
||||
fp_mul(&z, &x, &z);
|
||||
@ -710,6 +722,7 @@ const ltc_math_descriptor tfm_desc = {
|
||||
&lcm,
|
||||
|
||||
&mulmod,
|
||||
&sqrmod,
|
||||
&invmod,
|
||||
|
||||
&montgomery_setup,
|
||||
|
@ -42,6 +42,7 @@ int base64_encode(const unsigned char *in, unsigned long inlen,
|
||||
/* valid output size ? */
|
||||
len2 = 4 * ((inlen + 2) / 3);
|
||||
if (*outlen < len2 + 1) {
|
||||
*outlen = len2 + 1;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
p = out;
|
||||
|
@ -175,6 +175,9 @@ const char *crypt_build_settings =
|
||||
#endif
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(LTC_F8_MODE)
|
||||
" F8 MODE\n"
|
||||
#endif
|
||||
|
||||
"\nMACs:\n"
|
||||
#if defined(HMAC)
|
||||
|
@ -23,7 +23,7 @@
|
||||
void zeromem(void *out, size_t outlen)
|
||||
{
|
||||
unsigned char *mem = out;
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHKVD(out != NULL);
|
||||
while (outlen-- > 0) {
|
||||
*mem++ = 0;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc)
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
if ((unsigned long)cbc->blocklen > *len) {
|
||||
*len = cbc->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, cbc->IV, cbc->blocklen);
|
||||
|
@ -30,6 +30,7 @@ int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb)
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(cfb != NULL);
|
||||
if ((unsigned long)cfb->blocklen > *len) {
|
||||
*len = cfb->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, cfb->IV, cfb->blocklen);
|
||||
|
@ -30,6 +30,7 @@ int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr)
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
if ((unsigned long)ctr->blocklen > *len) {
|
||||
*len = ctr->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, ctr->ctr, ctr->blocklen);
|
||||
|
43
src/modes/f8/f8_decrypt.c
Normal file
43
src/modes/f8/f8_decrypt.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_decrypt.c
|
||||
F8 implementation, decrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
F8 decrypt
|
||||
@param ct Ciphertext
|
||||
@param pt [out] Plaintext
|
||||
@param len Length of ciphertext (octets)
|
||||
@param f8 F8 state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8)
|
||||
{
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
return f8_encrypt(ct, pt, len, f8);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
42
src/modes/f8/f8_done.c
Normal file
42
src/modes/f8/f8_done.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_done.c
|
||||
F8 implementation, finish chain, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/** Terminate the chain
|
||||
@param f8 The F8 chain to terminate
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int f8_done(symmetric_F8 *f8)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[f8->cipher].done(&f8->key);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
68
src/modes/f8/f8_encrypt.c
Normal file
68
src/modes/f8/f8_encrypt.c
Normal file
@ -0,0 +1,68 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_encrypt.c
|
||||
F8 implementation, encrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
F8 encrypt
|
||||
@param pt Plaintext
|
||||
@param ct [out] Ciphertext
|
||||
@param len Length of plaintext (octets)
|
||||
@param f8 F8 state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8)
|
||||
{
|
||||
int err, x;
|
||||
unsigned char buf[MAXBLOCKSIZE];
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if (f8->blocklen < 0 || f8->blocklen > (int)sizeof(f8->IV) ||
|
||||
f8->padlen < 0 || f8->padlen > (int)sizeof(f8->IV)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
zeromem(buf, sizeof(buf));
|
||||
while (len-- > 0) {
|
||||
if (f8->padlen == f8->blocklen) {
|
||||
/* xor of IV, MIV and blockcnt == what goes into cipher */
|
||||
STORE32H(f8->blockcnt, (buf+(f8->blocklen-4)));
|
||||
++(f8->blockcnt);
|
||||
for (x = 0; x < f8->blocklen; x++) {
|
||||
f8->IV[x] ^= f8->MIV[x] ^ buf[x];
|
||||
}
|
||||
if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
f8->padlen = 0;
|
||||
}
|
||||
*ct++ = *pt++ ^ f8->IV[f8->padlen++];
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
46
src/modes/f8/f8_getiv.c
Normal file
46
src/modes/f8/f8_getiv.c
Normal file
@ -0,0 +1,46 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ofb_getiv.c
|
||||
F8 implementation, get IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
Get the current initial vector
|
||||
@param IV [out] The destination of the initial vector
|
||||
@param len [in/out] The max size and resulting size of the initial vector
|
||||
@param f8 The F8 state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
if ((unsigned long)f8->blocklen > *len) {
|
||||
*len = f8->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, f8->IV, f8->blocklen);
|
||||
*len = f8->blocklen;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
52
src/modes/f8/f8_setiv.c
Normal file
52
src/modes/f8/f8_setiv.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_setiv.c
|
||||
F8 implementation, set IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
Set an initial vector
|
||||
@param IV The initial vector
|
||||
@param len The length of the vector (in octets)
|
||||
@param f8 The F8 state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len != (unsigned long)f8->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* force next block */
|
||||
f8->padlen = 0;
|
||||
return cipher_descriptor[f8->cipher].ecb_encrypt(IV, f8->IV, &f8->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
91
src/modes/f8/f8_start.c
Normal file
91
src/modes/f8/f8_start.c
Normal file
@ -0,0 +1,91 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_start.c
|
||||
F8 implementation, start chain, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
Initialize an F8 context
|
||||
@param cipher The index of the cipher desired
|
||||
@param IV The initial vector
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param salt_key The salting key for the IV
|
||||
@param skeylen The length of the salting key (octets)
|
||||
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
||||
@param f8 The F8 state to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_start( int cipher, const unsigned char *IV,
|
||||
const unsigned char *key, int keylen,
|
||||
const unsigned char *salt_key, int skeylen,
|
||||
int num_rounds, symmetric_F8 *f8)
|
||||
{
|
||||
int x, err;
|
||||
unsigned char tkey[MAXBLOCKSIZE];
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(salt_key != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy details */
|
||||
f8->blockcnt = 0;
|
||||
f8->cipher = cipher;
|
||||
f8->blocklen = cipher_descriptor[cipher].block_length;
|
||||
f8->padlen = f8->blocklen;
|
||||
|
||||
/* now get key ^ salt_key [extend salt_ket with 0x55 as required to match length] */
|
||||
for (x = 0; x < keylen && x < (int)sizeof(tkey); x++) {
|
||||
tkey[x] = key[x];
|
||||
}
|
||||
for (x = 0; x < skeylen && x < (int)sizeof(tkey); x++) {
|
||||
tkey[x] ^= salt_key[x];
|
||||
}
|
||||
for (; x < keylen && x < (int)sizeof(tkey); x++) {
|
||||
tkey[x] ^= 0x55;
|
||||
}
|
||||
|
||||
/* now encrypt with tkey[0..keylen-1] the IV and use that as the IV */
|
||||
if ((err = cipher_descriptor[cipher].setup(tkey, keylen, num_rounds, &f8->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* encrypt IV */
|
||||
if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(IV, f8->MIV, &f8->key)) != CRYPT_OK) {
|
||||
cipher_descriptor[f8->cipher].done(&f8->key);
|
||||
return err;
|
||||
}
|
||||
zeromem(tkey, sizeof(tkey));
|
||||
zeromem(f8->IV, sizeof(f8->IV));
|
||||
|
||||
/* terminate this cipher */
|
||||
cipher_descriptor[f8->cipher].done(&f8->key);
|
||||
|
||||
/* init the cipher */
|
||||
return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &f8->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
75
src/modes/f8/f8_test_mode.c
Normal file
75
src/modes/f8/f8_test_mode.c
Normal file
@ -0,0 +1,75 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_test_mode.c
|
||||
F8 implementation, test, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
int f8_test_mode(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
const unsigned char key[16] = { 0x23, 0x48, 0x29, 0x00, 0x84, 0x67, 0xbe, 0x18,
|
||||
0x6c, 0x3d, 0xe1, 0x4a, 0xae, 0x72, 0xd6, 0x2c };
|
||||
const unsigned char salt[4] = { 0x32, 0xf2, 0x87, 0x0d };
|
||||
const unsigned char IV[16] = { 0x00, 0x6e, 0x5c, 0xba, 0x50, 0x68, 0x1d, 0xe5,
|
||||
0x5c, 0x62, 0x15, 0x99, 0xd4, 0x62, 0x56, 0x4a };
|
||||
const unsigned char pt[39] = { 0x70, 0x73, 0x65, 0x75, 0x64, 0x6f, 0x72, 0x61,
|
||||
0x6e, 0x64, 0x6f, 0x6d, 0x6e, 0x65, 0x73, 0x73,
|
||||
0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
|
||||
0x6e, 0x65, 0x78, 0x74, 0x20, 0x62, 0x65, 0x73,
|
||||
0x74, 0x20, 0x74, 0x68, 0x69, 0x6e, 0x67 };
|
||||
const unsigned char ct[39] = { 0x01, 0x9c, 0xe7, 0xa2, 0x6e, 0x78, 0x54, 0x01,
|
||||
0x4a, 0x63, 0x66, 0xaa, 0x95, 0xd4, 0xee, 0xfd,
|
||||
0x1a, 0xd4, 0x17, 0x2a, 0x14, 0xf9, 0xfa, 0xf4,
|
||||
0x55, 0xb7, 0xf1, 0xd4, 0xb6, 0x2b, 0xd0, 0x8f,
|
||||
0x56, 0x2c, 0x0e, 0xef, 0x7c, 0x48, 0x02 };
|
||||
unsigned char buf[39];
|
||||
symmetric_F8 f8;
|
||||
int err, idx;
|
||||
|
||||
idx = find_cipher("aes");
|
||||
if (idx == -1) {
|
||||
idx = find_cipher("rijndael");
|
||||
if (idx == -1) return CRYPT_NOP;
|
||||
}
|
||||
|
||||
/* initialize the context */
|
||||
if ((err = f8_start(idx, IV, key, sizeof(key), salt, sizeof(salt), 0, &f8)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
f8_done(&f8);
|
||||
|
||||
/* encrypt block */
|
||||
if ((err = f8_encrypt(pt, buf, sizeof(pt), &f8)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* compare */
|
||||
if (XMEMCMP(buf, ct, sizeof(ct))) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
@ -30,6 +30,7 @@ int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw)
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(lrw != NULL);
|
||||
if (*len < 16) {
|
||||
*len = 16;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb)
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(ofb != NULL);
|
||||
if ((unsigned long)ofb->blocklen > *len) {
|
||||
*len = ofb->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, ofb->IV, ofb->blocklen);
|
||||
|
@ -78,6 +78,7 @@ int der_decode_bit_string(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* too many bits? */
|
||||
if (blen > *outlen) {
|
||||
*outlen = blen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ int der_encode_bit_string(const unsigned char *in, unsigned long inlen,
|
||||
}
|
||||
|
||||
if (len > *outlen) {
|
||||
*outlen = len;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ int der_encode_boolean(int in,
|
||||
LTC_ARGCHK(out != NULL);
|
||||
|
||||
if (*outlen < 3) {
|
||||
*outlen = 3;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ int der_decode_ia5_string(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* is it too long? */
|
||||
if (len > *outlen) {
|
||||
*outlen = len;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ int der_encode_ia5_string(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* too big? */
|
||||
if (len > *outlen) {
|
||||
*outlen = len;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen)
|
||||
}
|
||||
|
||||
if (*outlen < tmplen) {
|
||||
*outlen = tmplen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ int der_encode_object_identifier(unsigned long *words, unsigned long nwords,
|
||||
return err;
|
||||
}
|
||||
if (x > *outlen) {
|
||||
*outlen = x;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ int der_decode_octet_string(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* is it too long? */
|
||||
if (len > *outlen) {
|
||||
*outlen = len;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ int der_encode_octet_string(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* too big? */
|
||||
if (len > *outlen) {
|
||||
*outlen = len;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ int der_decode_printable_string(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* is it too long? */
|
||||
if (len > *outlen) {
|
||||
*outlen = len;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ int der_encode_printable_string(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* too big? */
|
||||
if (len > *outlen) {
|
||||
*outlen = len;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -153,6 +153,7 @@ int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
|
||||
|
||||
/* too big ? */
|
||||
if (*outlen < y) {
|
||||
*outlen = y;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ int der_encode_short_integer(unsigned long num, unsigned char *out, unsigned lon
|
||||
}
|
||||
|
||||
if (*outlen < len) {
|
||||
*outlen = len;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ int der_encode_utctime(ltc_utctime *utctime,
|
||||
return err;
|
||||
}
|
||||
if (tmplen > *outlen) {
|
||||
*outlen = tmplen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,7 @@ int dsa_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* avoid buffer overflow */
|
||||
if (*outlen < decode[2].size) {
|
||||
*outlen = decode[2].size;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
void dsa_free(dsa_key *key)
|
||||
{
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHKVD(key != NULL);
|
||||
mp_clear_multi(key->g, key->q, key->p, key->x, key->y, NULL);
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ int dsa_shared_secret(void *private_key, void *base,
|
||||
|
||||
x = (unsigned long)mp_unsigned_bin_size(res);
|
||||
if (*outlen < x) {
|
||||
*outlen = x;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
|
||||
/* avoid buffer overflow */
|
||||
if (*outlen < decode[2].size) {
|
||||
*outlen = decode[2].size;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
*/
|
||||
void ecc_free(ecc_key *key)
|
||||
{
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHKVD(key != NULL);
|
||||
mp_clear_multi(key->pubkey.x, key->pubkey.y, key->pubkey.z, key->k, NULL);
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,7 @@ int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
|
||||
|
||||
x = (unsigned long)mp_unsigned_bin_size(prime);
|
||||
if (*outlen < x) {
|
||||
*outlen = x;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
|
@ -26,8 +26,8 @@
|
||||
void ecc_sizes(int *low, int *high)
|
||||
{
|
||||
int i;
|
||||
LTC_ARGCHK(low != NULL);
|
||||
LTC_ARGCHK(high != NULL);
|
||||
LTC_ARGCHKVD(low != NULL);
|
||||
LTC_ARGCHKVD(high != NULL);
|
||||
|
||||
*low = INT_MAX;
|
||||
*high = 0;
|
||||
|
@ -48,7 +48,7 @@ void ltc_ecc_del_point(ecc_point *p)
|
||||
{
|
||||
/* prevents free'ing null arguments */
|
||||
if (p != NULL) {
|
||||
mp_clear_multi(p->x, p->y, p->z, NULL);
|
||||
mp_clear_multi(p->x, p->y, p->z, NULL); /* note: p->z may be NULL but that's ok with this function anyways */
|
||||
XFREE(p);
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void
|
||||
if ((err = mp_sub(modulus, Q->y, t1)) != CRYPT_OK) { goto done; }
|
||||
|
||||
if ( (mp_cmp(P->x, Q->x) == LTC_MP_EQ) &&
|
||||
(mp_cmp(P->z, Q->z) == LTC_MP_EQ) &&
|
||||
(Q->z != NULL && mp_cmp(P->z, Q->z) == LTC_MP_EQ) &&
|
||||
(mp_cmp(P->y, Q->y) == LTC_MP_EQ || mp_cmp(P->y, t1) == LTC_MP_EQ)) {
|
||||
mp_clear_multi(t1, t2, x, y, z, NULL);
|
||||
return ltc_ecc_projective_dbl_point(P, R, modulus, mp);
|
||||
@ -62,6 +62,7 @@ int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void
|
||||
if ((err = mp_copy(P->z, z)) != CRYPT_OK) { goto done; }
|
||||
|
||||
/* if Z is one then these are no-operations */
|
||||
if (Q->z != NULL) {
|
||||
/* T1 = Z' * Z' */
|
||||
if ((err = mp_sqr(Q->z, t1)) != CRYPT_OK) { goto done; }
|
||||
if ((err = mp_montgomery_reduce(t1, modulus, mp)) != CRYPT_OK) { goto done; }
|
||||
@ -74,6 +75,7 @@ int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void
|
||||
/* Y = Y * T1 */
|
||||
if ((err = mp_mul(t1, y, y)) != CRYPT_OK) { goto done; }
|
||||
if ((err = mp_montgomery_reduce(y, modulus, mp)) != CRYPT_OK) { goto done; }
|
||||
}
|
||||
|
||||
/* T1 = Z*Z */
|
||||
if ((err = mp_sqr(z, t1)) != CRYPT_OK) { goto done; }
|
||||
@ -120,9 +122,11 @@ int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void
|
||||
}
|
||||
|
||||
/* if Z' != 1 */
|
||||
if (Q->z != NULL) {
|
||||
/* Z = Z * Z' */
|
||||
if ((err = mp_mul(z, Q->z, z)) != CRYPT_OK) { goto done; }
|
||||
if ((err = mp_montgomery_reduce(z, modulus, mp)) != CRYPT_OK) { goto done; }
|
||||
}
|
||||
|
||||
/* Z = Z * X */
|
||||
if ((err = mp_mul(z, x, z)) != CRYPT_OK) { goto done; }
|
||||
|
@ -64,6 +64,7 @@ int katja_encrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
/* outlen must be at least the size of the modulus */
|
||||
modulus_bytelen = mp_unsigned_bin_size((key->N));
|
||||
if (modulus_bytelen > *outlen) {
|
||||
*outlen = modulus_bytelen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,7 @@ int katja_exptmod(const unsigned char *in, unsigned long inlen,
|
||||
/* read it back */
|
||||
x = (unsigned long)mp_unsigned_bin_size(key->N);
|
||||
if (x > *outlen) {
|
||||
*outlen = x;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
|
@ -154,6 +154,7 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
|
||||
|
||||
/* rest is the message (and skip 0x01) */
|
||||
if ((modulus_len - hLen - 1 - ++x) > *outlen) {
|
||||
*outlen = modulus_len - hLen - 1 - x;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
@ -135,6 +135,7 @@ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen,
|
||||
|
||||
/* create string of length modulus_len */
|
||||
if (*outlen < modulus_len) {
|
||||
*outlen = modulus_len;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
|
||||
|
||||
/* output is DB || hash || 0xBC */
|
||||
if (*outlen < modulus_len) {
|
||||
*outlen = modulus_len;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ int rsa_encrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
/* outlen must be at least the size of the modulus */
|
||||
modulus_bytelen = mp_unsigned_bin_size( (key->N));
|
||||
if (modulus_bytelen > *outlen) {
|
||||
*outlen = modulus_bytelen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,7 @@ int rsa_exptmod(const unsigned char *in, unsigned long inlen,
|
||||
/* read it back */
|
||||
x = (unsigned long)mp_unsigned_bin_size(key->N);
|
||||
if (x > *outlen) {
|
||||
*outlen = x;
|
||||
err = CRYPT_BUFFER_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
void rsa_free(rsa_key *key)
|
||||
{
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHKVD(key != NULL);
|
||||
mp_clear_multi( key->e, key->d, key->N, key->dQ, key->dP,
|
||||
key->qP, key->p, key->q, NULL);
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ int rsa_sign_hash(const unsigned char *in, unsigned long inlen,
|
||||
/* outlen must be at least the size of the modulus */
|
||||
modulus_bytelen = mp_unsigned_bin_size( (key->N));
|
||||
if (modulus_bytelen > *outlen) {
|
||||
*outlen = modulus_bytelen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,7 @@ static int fortuna_reseed(prng_state *prng)
|
||||
/* new K == SHA256(K || s) where s == SHA256(P0) || SHA256(P1) ... */
|
||||
sha256_init(&md);
|
||||
if ((err = sha256_process(&md, prng->fortuna.K, 32)) != CRYPT_OK) {
|
||||
sha256_done(&md, tmp);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -81,14 +82,19 @@ static int fortuna_reseed(prng_state *prng)
|
||||
if (x == 0 || ((prng->fortuna.reset_cnt >> (x-1)) & 1) == 0) {
|
||||
/* terminate this hash */
|
||||
if ((err = sha256_done(&prng->fortuna.pool[x], tmp)) != CRYPT_OK) {
|
||||
sha256_done(&md, tmp);
|
||||
return err;
|
||||
}
|
||||
/* add it to the string */
|
||||
if ((err = sha256_process(&md, tmp, 32)) != CRYPT_OK) {
|
||||
sha256_done(&md, tmp);
|
||||
return err;
|
||||
}
|
||||
/* reset this pool */
|
||||
sha256_init(&prng->fortuna.pool[x]);
|
||||
if ((err = sha256_init(&prng->fortuna.pool[x])) != CRYPT_OK) {
|
||||
sha256_done(&md, tmp);
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@ -123,13 +129,19 @@ static int fortuna_reseed(prng_state *prng)
|
||||
*/
|
||||
int fortuna_start(prng_state *prng)
|
||||
{
|
||||
int err, x;
|
||||
int err, x, y;
|
||||
unsigned char tmp[MAXBLOCKSIZE];
|
||||
|
||||
LTC_ARGCHK(prng != NULL);
|
||||
|
||||
/* initialize the pools */
|
||||
for (x = 0; x < FORTUNA_POOLS; x++) {
|
||||
sha256_init(&prng->fortuna.pool[x]);
|
||||
if ((err = sha256_init(&prng->fortuna.pool[x])) != CRYPT_OK) {
|
||||
for (y = 0; y < x; y++) {
|
||||
sha256_done(&prng->fortuna.pool[x], tmp);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
}
|
||||
prng->fortuna.pool_idx = prng->fortuna.pool0_len = prng->fortuna.reset_cnt =
|
||||
prng->fortuna.wd = 0;
|
||||
@ -137,6 +149,9 @@ int fortuna_start(prng_state *prng)
|
||||
/* reset bufs */
|
||||
zeromem(prng->fortuna.K, 32);
|
||||
if ((err = rijndael_setup(prng->fortuna.K, 32, 0, &prng->fortuna.skey)) != CRYPT_OK) {
|
||||
for (x = 0; x < FORTUNA_POOLS; x++) {
|
||||
sha256_done(&prng->fortuna.pool[x], tmp);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
zeromem(prng->fortuna.IV, 16);
|
||||
@ -312,6 +327,7 @@ int fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
|
||||
/* we'll write bytes for s&g's */
|
||||
if (*outlen < 32*FORTUNA_POOLS) {
|
||||
LTC_MUTEX_UNLOCK(&prng->fortuna.prng_lock);
|
||||
*outlen = 32*FORTUNA_POOLS;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -171,6 +171,7 @@ int rc4_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
|
||||
LTC_ARGCHK(prng != NULL);
|
||||
|
||||
if (*outlen < 32) {
|
||||
*outlen = 32;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -381,6 +381,7 @@ int sober128_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
|
||||
LTC_ARGCHK(prng != NULL);
|
||||
|
||||
if (*outlen < 64) {
|
||||
*outlen = 64;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -273,6 +273,7 @@ int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
|
||||
/* we'll write 64 bytes for s&g's */
|
||||
if (*outlen < 64) {
|
||||
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
||||
*outlen = 64;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -63,19 +63,19 @@ static void der_set_test(void)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
strcpy(strs[0], "one");
|
||||
strcpy(strs[1], "one2");
|
||||
strcpy(strs[2], "two");
|
||||
strcpy(strs[3], "aaa");
|
||||
strcpy(strs[4], "aaaa");
|
||||
strcpy(strs[5], "aab");
|
||||
strcpy(strs[6], "aaab");
|
||||
strcpy(strs[7], "bbb");
|
||||
strcpy(strs[8], "bbba");
|
||||
strcpy(strs[9], "bbbb");
|
||||
strcpy((char*)strs[0], "one");
|
||||
strcpy((char*)strs[1], "one2");
|
||||
strcpy((char*)strs[2], "two");
|
||||
strcpy((char*)strs[3], "aaa");
|
||||
strcpy((char*)strs[4], "aaaa");
|
||||
strcpy((char*)strs[5], "aab");
|
||||
strcpy((char*)strs[6], "aaab");
|
||||
strcpy((char*)strs[7], "bbb");
|
||||
strcpy((char*)strs[8], "bbba");
|
||||
strcpy((char*)strs[9], "bbbb");
|
||||
|
||||
for (x = 0; x < 10; x++) {
|
||||
LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], strlen(strs[x]));
|
||||
LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], strlen((char*)strs[x]));
|
||||
}
|
||||
|
||||
outlen = sizeof(outbuf);
|
||||
@ -96,8 +96,8 @@ static void der_set_test(void)
|
||||
|
||||
/* now compare */
|
||||
for (x = 1; x < 10; x++) {
|
||||
if (!(strlen(strs[x-1]) <= strlen(strs[x])) && strcmp(strs[x-1], strs[x]) >= 0) {
|
||||
fprintf(stderr, "error SET OF order at %d is wrong\n", x);
|
||||
if (!(strlen((char*)strs[x-1]) <= strlen((char*)strs[x])) && strcmp((char*)strs[x-1], (char*)strs[x]) >= 0) {
|
||||
fprintf(stderr, "error SET OF order at %lu is wrong\n", x);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -638,7 +638,7 @@ int der_tests(void)
|
||||
|
||||
/* test OID */
|
||||
x = sizeof(buf[0]);
|
||||
DO(der_encode_object_identifier(rsa_oid, sizeof(rsa_oid)/sizeof(rsa_oid[0]), buf[0], &x));
|
||||
DO(der_encode_object_identifier((unsigned long*)rsa_oid, sizeof(rsa_oid)/sizeof(rsa_oid[0]), buf[0], &x));
|
||||
if (x != sizeof(rsa_oid_der) || memcmp(rsa_oid_der, buf[0], x)) {
|
||||
fprintf(stderr, "rsa_oid_der encode failed to match, %lu, ", x);
|
||||
for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]);
|
||||
@ -698,45 +698,45 @@ int der_tests(void)
|
||||
|
||||
/* IA5 string */
|
||||
x = sizeof(buf[0]);
|
||||
DO(der_encode_ia5_string(rsa_ia5, strlen(rsa_ia5), buf[0], &x));
|
||||
DO(der_encode_ia5_string(rsa_ia5, strlen((char*)rsa_ia5), buf[0], &x));
|
||||
if (x != sizeof(rsa_ia5_der) || memcmp(buf[0], rsa_ia5_der, x)) {
|
||||
fprintf(stderr, "IA5 encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_ia5_der));
|
||||
return 1;
|
||||
}
|
||||
DO(der_length_ia5_string(rsa_ia5, strlen(rsa_ia5), &y));
|
||||
DO(der_length_ia5_string(rsa_ia5, strlen((char*)rsa_ia5), &y));
|
||||
if (y != x) {
|
||||
fprintf(stderr, "IA5 length failed to match: %lu, %lu\n", x, y);
|
||||
return 1;
|
||||
}
|
||||
y = sizeof(buf[1]);
|
||||
DO(der_decode_ia5_string(buf[0], x, buf[1], &y));
|
||||
if (y != strlen(rsa_ia5) || memcmp(buf[1], rsa_ia5, strlen(rsa_ia5))) {
|
||||
if (y != strlen((char*)rsa_ia5) || memcmp(buf[1], rsa_ia5, strlen((char*)rsa_ia5))) {
|
||||
fprintf(stderr, "DER IA5 failed test vector\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Printable string */
|
||||
x = sizeof(buf[0]);
|
||||
DO(der_encode_printable_string(rsa_printable, strlen(rsa_printable), buf[0], &x));
|
||||
DO(der_encode_printable_string(rsa_printable, strlen((char*)rsa_printable), buf[0], &x));
|
||||
if (x != sizeof(rsa_printable_der) || memcmp(buf[0], rsa_printable_der, x)) {
|
||||
fprintf(stderr, "PRINTABLE encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_printable_der));
|
||||
return 1;
|
||||
}
|
||||
DO(der_length_printable_string(rsa_printable, strlen(rsa_printable), &y));
|
||||
DO(der_length_printable_string(rsa_printable, strlen((char*)rsa_printable), &y));
|
||||
if (y != x) {
|
||||
fprintf(stderr, "printable length failed to match: %lu, %lu\n", x, y);
|
||||
return 1;
|
||||
}
|
||||
y = sizeof(buf[1]);
|
||||
DO(der_decode_printable_string(buf[0], x, buf[1], &y));
|
||||
if (y != strlen(rsa_printable) || memcmp(buf[1], rsa_printable, strlen(rsa_printable))) {
|
||||
if (y != strlen((char*)rsa_printable) || memcmp(buf[1], rsa_printable, strlen((char*)rsa_printable))) {
|
||||
fprintf(stderr, "DER printable failed test vector\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Test UTC time */
|
||||
x = sizeof(buf[0]);
|
||||
DO(der_encode_utctime(&rsa_time1, buf[0], &x));
|
||||
DO(der_encode_utctime((ltc_utctime*)&rsa_time1, buf[0], &x));
|
||||
if (x != sizeof(rsa_time1_der) || memcmp(buf[0], rsa_time1_der, x)) {
|
||||
fprintf(stderr, "UTCTIME encode of rsa_time1 failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_time1_der));
|
||||
fprintf(stderr, "\n\n");
|
||||
@ -744,7 +744,7 @@ for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]); printf("\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
DO(der_length_utctime(&rsa_time1, &y));
|
||||
DO(der_length_utctime((ltc_utctime*)&rsa_time1, &y));
|
||||
if (y != x) {
|
||||
fprintf(stderr, "UTCTIME length failed to match for rsa_time1: %lu, %lu\n", x, y);
|
||||
return 1;
|
||||
@ -766,7 +766,7 @@ tmp_time.off_hh);
|
||||
}
|
||||
|
||||
x = sizeof(buf[0]);
|
||||
DO(der_encode_utctime(&rsa_time2, buf[0], &x));
|
||||
DO(der_encode_utctime((ltc_utctime*)&rsa_time2, buf[0], &x));
|
||||
if (x != sizeof(rsa_time2_der) || memcmp(buf[0], rsa_time2_der, x)) {
|
||||
fprintf(stderr, "UTCTIME encode of rsa_time2 failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_time1_der));
|
||||
fprintf(stderr, "\n\n");
|
||||
@ -774,7 +774,7 @@ for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]); printf("\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
DO(der_length_utctime(&rsa_time2, &y));
|
||||
DO(der_length_utctime((ltc_utctime*)&rsa_time2, &y));
|
||||
if (y != x) {
|
||||
fprintf(stderr, "UTCTIME length failed to match for rsa_time2: %lu, %lu\n", x, y);
|
||||
return 1;
|
||||
|
@ -7,7 +7,7 @@ endif
|
||||
|
||||
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \
|
||||
dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \
|
||||
store_test.o test.o x86_prof.o katja_test.o
|
||||
store_test.o test_driver.o x86_prof.o katja_test.o
|
||||
|
||||
ifndef LIBTEST_S
|
||||
LIBTEST_S=libtomcrypt_prof.a
|
||||
|
@ -3,7 +3,7 @@ CC=icc
|
||||
|
||||
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \
|
||||
dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \
|
||||
store_test.o test.o x86_prof.o katja_test.o
|
||||
store_test.o test_driver.o x86_prof.o katja_test.o
|
||||
|
||||
ifndef LIBTEST_S
|
||||
LIBTEST_S = libtomcrypt_prof.a
|
||||
|
@ -2,7 +2,7 @@ CFLAGS = /I../src/headers/ /I./ /Ox /DWIN32 /DLTC_SOURCE /W3 /Fo$@
|
||||
|
||||
OBJECTS=base64_test.obj cipher_hash_test.obj der_tests.obj \
|
||||
dsa_test.obj ecc_test.obj mac_test.obj modes_test.obj pkcs_1_test.obj \
|
||||
rsa_test.obj store_test.obj test.obj x86_prof.obj katja_test.obj
|
||||
rsa_test.obj store_test.obj test_driver.obj x86_prof.obj katja_test.obj
|
||||
|
||||
tomcrypt_prof.lib: $(OBJECTS)
|
||||
lib /out:tomcrypt_prof.lib $(OBJECTS)
|
||||
|
@ -9,7 +9,7 @@ endif
|
||||
|
||||
OBJECTS = base64_test.o cipher_hash_test.o der_tests.o \
|
||||
dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o \
|
||||
store_test.o test.o x86_prof.o katja_test.o
|
||||
store_test.o test_driver.o x86_prof.o katja_test.o
|
||||
|
||||
ifndef LIBTEST
|
||||
LIBTEST=libtomcrypt_prof.la
|
||||
|
@ -31,6 +31,10 @@ int modes_test(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
DO(f8_test_mode());
|
||||
#endif
|
||||
|
||||
#ifdef LRW_MODE
|
||||
DO(lrw_test());
|
||||
#endif
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <tomcrypt.h>
|
||||
|
||||
/* enable stack testing */
|
||||
// #define STACK_TEST
|
||||
/* #define STACK_TEST */
|
||||
|
||||
/* stack testing, define this if stack usage goes downwards [e.g. x86] */
|
||||
#define STACK_DOWN
|
||||
|
@ -18,7 +18,7 @@ void tally_results(int type)
|
||||
{
|
||||
int x;
|
||||
|
||||
// qsort the results
|
||||
/* qsort the results */
|
||||
qsort(results, no_results, sizeof(struct list), &sorter);
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
@ -75,7 +75,7 @@ ulong64 rdtsc (void)
|
||||
return XCLOCK();
|
||||
#endif
|
||||
|
||||
// Microsoft and Intel Windows compilers
|
||||
/* Microsoft and Intel Windows compilers */
|
||||
#elif defined _M_IX86 && !defined(LTC_NO_ASM)
|
||||
__asm rdtsc
|
||||
#elif defined _M_AMD64 && !defined(LTC_NO_ASM)
|
||||
@ -627,7 +627,7 @@ int time_hash(void)
|
||||
}
|
||||
|
||||
#undef MPI
|
||||
//#warning you need an mp_rand!!!
|
||||
/*#warning you need an mp_rand!!!*/
|
||||
|
||||
#ifdef MPI
|
||||
void time_mult(void)
|
||||
@ -781,7 +781,7 @@ void time_rsa(void)
|
||||
t_start();
|
||||
t1 = t_read();
|
||||
z = sizeof(buf[1]);
|
||||
if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng,
|
||||
if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, (const unsigned char *)"testprog", 8, &yarrow_prng,
|
||||
find_prng("yarrow"), find_hash("sha1"),
|
||||
&key)) != CRYPT_OK) {
|
||||
fprintf(stderr, "\n\nrsa_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
|
||||
@ -798,7 +798,7 @@ void time_rsa(void)
|
||||
t_start();
|
||||
t1 = t_read();
|
||||
zzz = sizeof(buf[0]);
|
||||
if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8, find_hash("sha1"),
|
||||
if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, (const unsigned char *)"testprog", 8, find_hash("sha1"),
|
||||
&zz, &key)) != CRYPT_OK) {
|
||||
fprintf(stderr, "\n\nrsa_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
|
||||
exit(EXIT_FAILURE);
|
||||
@ -916,7 +916,7 @@ void time_ecc(void)
|
||||
|
||||
for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
|
||||
t2 = 0;
|
||||
for (y = 0; y < 64; y++) {
|
||||
for (y = 0; y < 256; y++) {
|
||||
t_start();
|
||||
t1 = t_read();
|
||||
if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) {
|
||||
@ -926,15 +926,15 @@ void time_ecc(void)
|
||||
t1 = t_read() - t1;
|
||||
t2 += t1;
|
||||
|
||||
if (y < 63) {
|
||||
if (y < 255) {
|
||||
ecc_free(&key);
|
||||
}
|
||||
}
|
||||
t2 >>= 6;
|
||||
t2 >>= 8;
|
||||
fprintf(stderr, "ECC-%lu make_key took %15llu cycles\n", x*8, t2);
|
||||
|
||||
t2 = 0;
|
||||
for (y = 0; y < 16; y++) {
|
||||
for (y = 0; y < 256; y++) {
|
||||
t_start();
|
||||
t1 = t_read();
|
||||
z = sizeof(buf[1]);
|
||||
@ -946,7 +946,7 @@ void time_ecc(void)
|
||||
t1 = t_read() - t1;
|
||||
t2 += t1;
|
||||
}
|
||||
t2 >>= 4;
|
||||
t2 >>= 8;
|
||||
fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
|
||||
ecc_free(&key);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user