diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-09-06 17:20:33 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-09-06 17:26:58 +0200 |
commit | e6177630198eb1eea2def0374fae1196da0e40ec (patch) | |
tree | 704951804609999fb6ef7a956b04921b9f84c320 /libtomcrypt/headers | |
parent | 943f9ab50c110133a5cd1118b5b19cb09301168f (diff) | |
download | cryptodev-linux-e6177630198eb1eea2def0374fae1196da0e40ec.tar.gz cryptodev-linux-e6177630198eb1eea2def0374fae1196da0e40ec.tar.xz cryptodev-linux-e6177630198eb1eea2def0374fae1196da0e40ec.zip |
Run Lindent on libtom(*)
Diffstat (limited to 'libtomcrypt/headers')
-rw-r--r-- | libtomcrypt/headers/tomcrypt.h | 65 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_argchk.h | 3 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_cfg.h | 91 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_custom.h | 175 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_hash.h | 12 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_macros.h | 114 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_math.h | 3 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_misc.h | 8 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_pk.h | 370 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_pkcs.h | 78 | ||||
-rw-r--r-- | libtomcrypt/headers/tomcrypt_prng.h | 45 |
11 files changed, 478 insertions, 486 deletions
diff --git a/libtomcrypt/headers/tomcrypt.h b/libtomcrypt/headers/tomcrypt.h index a9c675d..7c5f110 100644 --- a/libtomcrypt/headers/tomcrypt.h +++ b/libtomcrypt/headers/tomcrypt.h @@ -26,42 +26,42 @@ extern "C" { #define TAB_SIZE 32 /* error codes [will be expanded in future releases] */ -enum { - CRYPT_OK=0, /* Result OK */ - CRYPT_ERROR, /* Generic Error */ - CRYPT_NOP, /* Not a failure but no operation was performed */ + enum { + CRYPT_OK = 0, /* Result OK */ + CRYPT_ERROR, /* Generic Error */ + CRYPT_NOP, /* Not a failure but no operation was performed */ - CRYPT_INVALID_KEYSIZE, /* Invalid key size given */ - CRYPT_INVALID_ROUNDS, /* Invalid number of rounds */ - CRYPT_FAIL_TESTVECTOR, /* Algorithm failed test vectors */ + CRYPT_INVALID_KEYSIZE, /* Invalid key size given */ + CRYPT_INVALID_ROUNDS, /* Invalid number of rounds */ + CRYPT_FAIL_TESTVECTOR, /* Algorithm failed test vectors */ - CRYPT_BUFFER_OVERFLOW, /* Not enough space for output */ - CRYPT_INVALID_PACKET, /* Invalid input packet given */ + CRYPT_BUFFER_OVERFLOW, /* Not enough space for output */ + CRYPT_INVALID_PACKET, /* Invalid input packet given */ - CRYPT_INVALID_PRNGSIZE, /* Invalid number of bits for a PRNG */ - CRYPT_ERROR_READPRNG, /* Could not read enough from PRNG */ + CRYPT_INVALID_PRNGSIZE, /* Invalid number of bits for a PRNG */ + CRYPT_ERROR_READPRNG, /* Could not read enough from PRNG */ - CRYPT_INVALID_CIPHER, /* Invalid cipher specified */ - CRYPT_INVALID_HASH, /* Invalid hash specified */ - CRYPT_INVALID_PRNG, /* Invalid PRNG specified */ + CRYPT_INVALID_CIPHER, /* Invalid cipher specified */ + CRYPT_INVALID_HASH, /* Invalid hash specified */ + CRYPT_INVALID_PRNG, /* Invalid PRNG specified */ - CRYPT_MEM, /* Out of memory */ + CRYPT_MEM, /* Out of memory */ - CRYPT_PK_TYPE_MISMATCH, /* Not equivalent types of PK keys */ - CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */ + CRYPT_PK_TYPE_MISMATCH, /* Not equivalent types of PK keys */ + CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */ - CRYPT_INVALID_ARG, /* Generic invalid argument */ - CRYPT_FILE_NOTFOUND, /* File Not Found */ + CRYPT_INVALID_ARG, /* Generic invalid argument */ + CRYPT_FILE_NOTFOUND, /* File Not Found */ - CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */ - CRYPT_PK_INVALID_SYSTEM,/* Invalid PK system specified */ - CRYPT_PK_DUP, /* Duplicate key already in key ring */ - CRYPT_PK_NOT_FOUND, /* Key not found in keyring */ - CRYPT_PK_INVALID_SIZE, /* Invalid size input for PK parameters */ + CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */ + CRYPT_PK_INVALID_SYSTEM, /* Invalid PK system specified */ + CRYPT_PK_DUP, /* Duplicate key already in key ring */ + CRYPT_PK_NOT_FOUND, /* Key not found in keyring */ + CRYPT_PK_INVALID_SIZE, /* Invalid size input for PK parameters */ - CRYPT_INVALID_PRIME_SIZE,/* Invalid size of prime requested */ - CRYPT_PK_INVALID_PADDING /* Invalid padding on input */ -}; + CRYPT_INVALID_PRIME_SIZE, /* Invalid size of prime requested */ + CRYPT_PK_INVALID_PADDING /* Invalid padding on input */ + }; #include <tomcrypt_cfg.h> #include <tomcrypt_macros.h> @@ -73,12 +73,7 @@ enum { #include <tomcrypt_pkcs.h> #ifdef __cplusplus - } +} #endif - -#endif /* TOMCRYPT_H_ */ - - -/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt.h,v $ */ -/* $Revision: 1.21 $ */ -/* $Date: 2006/12/16 19:34:05 $ */ +#endif /* TOMCRYPT_H_ */ +/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt.h,v $ *//* $Revision: 1.21 $ *//* $Date: 2006/12/16 19:34:05 $ */ diff --git a/libtomcrypt/headers/tomcrypt_argchk.h b/libtomcrypt/headers/tomcrypt_argchk.h index 1ba08c7..c63b4e3 100644 --- a/libtomcrypt/headers/tomcrypt_argchk.h +++ b/libtomcrypt/headers/tomcrypt_argchk.h @@ -20,7 +20,7 @@ void crypt_argchk(char *v, char *s, int d); #elif ARGTYPE == 3 -#define LTC_ARGCHK(x) +#define LTC_ARGCHK(x) #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) #elif ARGTYPE == 4 @@ -30,7 +30,6 @@ void crypt_argchk(char *v, char *s, int d); #endif - /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_argchk.h,v $ */ /* $Revision: 1.5 $ */ /* $Date: 2006/08/27 20:50:21 $ */ diff --git a/libtomcrypt/headers/tomcrypt_cfg.h b/libtomcrypt/headers/tomcrypt_cfg.h index 93db10e..7bcf6cc 100644 --- a/libtomcrypt/headers/tomcrypt_cfg.h +++ b/libtomcrypt/headers/tomcrypt_cfg.h @@ -11,7 +11,7 @@ #define LTC_CALL __cdecl #else #ifndef LTC_CALL - #define LTC_CALL +#define LTC_CALL #endif #endif @@ -22,29 +22,30 @@ /* certain platforms use macros for these, making the prototypes broken */ #ifndef LTC_NO_PROTOTYPES -LTC_EXPORT void LTC_CALL XQSORT(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); +LTC_EXPORT void LTC_CALL XQSORT(void *base, size_t nmemb, size_t size, + int (*compar) (const void *, const void *)); /* you can change how memory allocation works ... */ -LTC_EXPORT void * LTC_CALL XMALLOC(size_t n); -LTC_EXPORT void * LTC_CALL XREALLOC(void *p, size_t n); -LTC_EXPORT void * LTC_CALL XCALLOC(size_t n, size_t s); +LTC_EXPORT void *LTC_CALL XMALLOC(size_t n); +LTC_EXPORT void *LTC_CALL XREALLOC(void *p, size_t n); +LTC_EXPORT void *LTC_CALL XCALLOC(size_t n, size_t s); LTC_EXPORT void LTC_CALL XFREE(void *p); /* change the clock function too */ LTC_EXPORT clock_t LTC_CALL XCLOCK(void); /* various other functions */ -LTC_EXPORT void * LTC_CALL XMEMCPY(void *dest, const void *src, size_t n); -LTC_EXPORT int LTC_CALL XMEMCMP(const void *s1, const void *s2, size_t n); -LTC_EXPORT void * LTC_CALL XMEMSET(void *s, int c, size_t n); +LTC_EXPORT void *LTC_CALL XMEMCPY(void *dest, const void *src, size_t n); +LTC_EXPORT int LTC_CALL XMEMCMP(const void *s1, const void *s2, size_t n); +LTC_EXPORT void *LTC_CALL XMEMSET(void *s, int c, size_t n); -LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); +LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #endif /* type of argument checking, 0=default, 1=fatal and 2=error+continue, 3=nothing, 4=return error */ #ifndef ARGTYPE - #define ARGTYPE 4 +#define ARGTYPE 4 #endif /* Controls endianess and size of registers. Leave uncommented to get platform neutral [slower] code @@ -56,61 +57,60 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); /* detect x86-32 machines somewhat */ #if !defined(__STRICT_ANSI__) && (defined(INTEL_CC) || (defined(_MSC_VER) && defined(WIN32)) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__)))) - #define ENDIAN_LITTLE - #define ENDIAN_32BITWORD - #define LTC_FAST - #define LTC_FAST_TYPE unsigned long +#define ENDIAN_LITTLE +#define ENDIAN_32BITWORD +#define LTC_FAST +#define LTC_FAST_TYPE unsigned long #endif /* detects MIPS R5900 processors (PS2) */ #if (defined(__R5900) || defined(R5900) || defined(__R5900__)) && (defined(_mips) || defined(__mips__) || defined(mips)) - #define ENDIAN_LITTLE - #define ENDIAN_64BITWORD +#define ENDIAN_LITTLE +#define ENDIAN_64BITWORD #endif /* detect amd64 */ #if !defined(__STRICT_ANSI__) && defined(__x86_64__) - #define ENDIAN_LITTLE - #define ENDIAN_64BITWORD - #define LTC_FAST - #define LTC_FAST_TYPE unsigned long +#define ENDIAN_LITTLE +#define ENDIAN_64BITWORD +#define LTC_FAST +#define LTC_FAST_TYPE unsigned long #endif /* detect PPC32 */ #if !defined(__STRICT_ANSI__) && defined(LTC_PPC32) - #define ENDIAN_BIG - #define ENDIAN_32BITWORD - #define LTC_FAST - #define LTC_FAST_TYPE unsigned long -#endif +#define ENDIAN_BIG +#define ENDIAN_32BITWORD +#define LTC_FAST +#define LTC_FAST_TYPE unsigned long +#endif /* detect sparc and sparc64 */ #if defined(__sparc__) - #define ENDIAN_BIG - #if defined(__arch64__) - #define ENDIAN_64BITWORD - #else - #define ENDIAN_32BITWORD - #endif +#define ENDIAN_BIG +#if defined(__arch64__) +#define ENDIAN_64BITWORD +#else +#define ENDIAN_32BITWORD +#endif #endif - #ifdef LTC_NO_FAST - #ifdef LTC_FAST - #undef LTC_FAST - #endif +#ifdef LTC_FAST +#undef LTC_FAST +#endif #endif /* No asm is a quick way to disable anything "not portable" */ #ifdef LTC_NO_ASM - #undef ENDIAN_LITTLE - #undef ENDIAN_BIG - #undef ENDIAN_32BITWORD - #undef ENDIAN_64BITWORD - #undef LTC_FAST - #undef LTC_FAST_TYPE - #define LTC_NO_ROLC - #define LTC_NO_BSWAP +#undef ENDIAN_LITTLE +#undef ENDIAN_BIG +#undef ENDIAN_32BITWORD +#undef ENDIAN_64BITWORD +#undef LTC_FAST +#undef LTC_FAST_TYPE +#define LTC_NO_ROLC +#define LTC_NO_BSWAP #endif /* #define ENDIAN_LITTLE */ @@ -120,16 +120,15 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); /* #define ENDIAN_64BITWORD */ #if (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD)) - #error You must specify a word size as well as endianess in tomcrypt_cfg.h +#error You must specify a word size as well as endianess in tomcrypt_cfg.h #endif #if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) - #define ENDIAN_NEUTRAL +#define ENDIAN_NEUTRAL #endif #endif - /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_cfg.h,v $ */ /* $Revision: 1.19 $ */ /* $Date: 2006/12/04 02:19:48 $ */ diff --git a/libtomcrypt/headers/tomcrypt_custom.h b/libtomcrypt/headers/tomcrypt_custom.h index 76b5744..bd5c813 100644 --- a/libtomcrypt/headers/tomcrypt_custom.h +++ b/libtomcrypt/headers/tomcrypt_custom.h @@ -5,52 +5,52 @@ /* macros for various libc functions you can change for embedded targets */ #ifndef XMALLOC - #ifdef malloc - #define LTC_NO_PROTOTYPES - #endif +#ifdef malloc +#define LTC_NO_PROTOTYPES +#endif #define XMALLOC(x) kmalloc(x, GFP_KERNEL) #endif #ifndef XREALLOC - #ifdef realloc - #define LTC_NO_PROTOTYPES - #endif +#ifdef realloc +#define LTC_NO_PROTOTYPES +#endif #define XREALLOC(x,y) krealloc(x,y,GFP_KERNEL) #endif #ifndef XCALLOC - #ifdef calloc - #define LTC_NO_PROTOTYPES - #endif +#ifdef calloc +#define LTC_NO_PROTOTYPES +#endif #define XCALLOC(x,y) kcalloc(x, y, GFP_KERNEL) #endif #ifndef XFREE - #ifdef free - #define LTC_NO_PROTOTYPES - #endif +#ifdef free +#define LTC_NO_PROTOTYPES +#endif #define XFREE kfree #endif #ifndef XMEMSET - #ifdef memset - #define LTC_NO_PROTOTYPES - #endif +#ifdef memset +#define LTC_NO_PROTOTYPES +#endif #define XMEMSET memset #endif #ifndef XMEMCPY - #ifdef memcpy - #define LTC_NO_PROTOTYPES - #endif +#ifdef memcpy +#define LTC_NO_PROTOTYPES +#endif #define XMEMCPY memcpy #endif #ifndef XMEMCMP - #ifdef memcmp - #define LTC_NO_PROTOTYPES - #endif +#ifdef memcmp +#define LTC_NO_PROTOTYPES +#endif #define XMEMCMP memcmp #endif #ifndef XSTRCMP - #ifdef strcmp - #define LTC_NO_PROTOTYPES - #endif +#ifdef strcmp +#define LTC_NO_PROTOTYPES +#endif #define XSTRCMP strcmp #endif @@ -62,54 +62,54 @@ #endif #ifndef XQSORT - #ifdef qsort - #define LTC_NO_PROTOTYPES - #endif +#ifdef qsort +#define LTC_NO_PROTOTYPES +#endif #define XQSORT(x,y,z,w) sort(x,y,z,w,NULL) #endif /* Easy button? */ #ifdef LTC_EASY - #define LTC_NO_CIPHERS - #define LTC_RIJNDAEL - #define LTC_BLOWFISH - #define LTC_DES - #define LTC_CAST5 - - #define LTC_NO_MODES - #define LTC_ECB_MODE - #define LTC_CBC_MODE - #define LTC_CTR_MODE - - #define LTC_NO_HASHES - #define LTC_SHA1 - #define LTC_SHA512 - #define LTC_SHA384 - #define LTC_SHA256 - #define LTC_SHA224 - - #define LTC_NO_MACS - #define LTC_HMAC - #define LTC_OMAC - #define LTC_CCM_MODE - - #define LTC_NO_PRNGS - #define LTC_SPRNG - #define LTC_YARROW - #define LTC_DEVRANDOM - #define TRY_URANDOM_FIRST - - #define LTC_NO_PK - #define LTC_MRSA - #define LTC_MECC -#endif +#define LTC_NO_CIPHERS +#define LTC_RIJNDAEL +#define LTC_BLOWFISH +#define LTC_DES +#define LTC_CAST5 + +#define LTC_NO_MODES +#define LTC_ECB_MODE +#define LTC_CBC_MODE +#define LTC_CTR_MODE + +#define LTC_NO_HASHES +#define LTC_SHA1 +#define LTC_SHA512 +#define LTC_SHA384 +#define LTC_SHA256 +#define LTC_SHA224 + +#define LTC_NO_MACS +#define LTC_HMAC +#define LTC_OMAC +#define LTC_CCM_MODE + +#define LTC_NO_PRNGS +#define LTC_SPRNG +#define LTC_YARROW +#define LTC_DEVRANDOM +#define TRY_URANDOM_FIRST + +#define LTC_NO_PK +#define LTC_MRSA +#define LTC_MECC +#endif /* Use small code where possible */ /* #define LTC_SMALL_CODE */ /* Enable self-test test vector checking */ #ifndef LTC_NO_TEST - #define LTC_TEST +#define LTC_TEST #endif /* clean the stack of functions which put private information on stack */ @@ -141,10 +141,10 @@ * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */ #define LTC_TWOFISH #ifndef LTC_NO_TABLES - #define LTC_TWOFISH_TABLES +#define LTC_TWOFISH_TABLES /* #define LTC_TWOFISH_ALL_TABLES */ #else - #define LTC_TWOFISH_SMALL +#define LTC_TWOFISH_SMALL #endif /* #define LTC_TWOFISH_SMALL */ /* LTC_DES includes EDE triple-LTC_DES */ @@ -161,7 +161,6 @@ #endif /* LTC_NO_CIPHERS */ - /* ---> Block Cipher Modes of Operation <--- */ #ifndef LTC_NO_MODES @@ -180,7 +179,7 @@ /* like GCM mode this will enable 16 8x128 tables [64KB] that make * seeking very fast. */ - #define LRW_TABLES +#define LRW_TABLES #endif /* XTS mode */ @@ -189,7 +188,7 @@ #endif /* LTC_NO_MODES */ /* ---> One-Way Hash Functions <--- */ -#ifndef LTC_NO_HASHES +#ifndef LTC_NO_HASHES #define LTC_CHC_HASH #define LTC_WHIRLPOOL @@ -220,14 +219,14 @@ #define LTC_PELICAN #if defined(LTC_PELICAN) && !defined(LTC_RIJNDAEL) - #error Pelican-MAC requires LTC_RIJNDAEL +#error Pelican-MAC requires LTC_RIJNDAEL #endif /* ---> Encrypt + Authenticate Modes <--- */ #define LTC_EAX_MODE #if defined(LTC_EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(LTC_OMAC)) - #error LTC_EAX_MODE requires CTR and LTC_OMAC mode +#error LTC_EAX_MODE requires CTR and LTC_OMAC mode #endif #define LTC_OCB_MODE @@ -236,7 +235,7 @@ /* Use 64KiB tables */ #ifndef LTC_NO_TABLES - #define LTC_GCM_TABLES +#define LTC_GCM_TABLES #endif /* USE SSE2? requires GCC works on x86_32 and x86_64*/ @@ -259,7 +258,7 @@ #define LTC_YARROW_AES 0 #if defined(LTC_YARROW) && !defined(LTC_CTR_MODE) - #error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined! +#error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined! #endif /* a PRNG that simply reads from an available system source */ @@ -303,7 +302,7 @@ #define LTC_MRSA /* Include Katja (a Rabin variant like RSA) */ -/* #define MKAT */ +/* #define MKAT */ /* Digital Signature Algorithm */ #define LTC_MDSA @@ -315,8 +314,8 @@ #define LTC_ECC_SHAMIR #if defined(TFM_LTC_DESC) && defined(LTC_MECC) - #define LTC_MECC_ACCEL -#endif +#define LTC_MECC_ACCEL +#endif /* do we want fixed point ECC */ /* #define LTC_MECC_FP */ @@ -342,32 +341,32 @@ #ifdef LTC_MECC /* Supported ECC Key Sizes */ #ifndef LTC_NO_CURVES - #define ECC112 - #define ECC128 - #define ECC160 - #define ECC192 - #define ECC224 - #define ECC256 - #define ECC384 - #define ECC521 +#define ECC112 +#define ECC128 +#define ECC160 +#define ECC192 +#define ECC224 +#define ECC256 +#define ECC384 +#define ECC521 #endif #endif #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(MKATJA) /* Include the MPI functionality? (required by the PK algorithms) */ - #define MPI +#define MPI #endif #ifdef LTC_MRSA - #define LTC_PKCS_1 -#endif +#define LTC_PKCS_1 +#endif -#if defined(LTC_DER) && !defined(MPI) - #error ASN.1 DER requires MPI functionality +#if defined(LTC_DER) && !defined(MPI) +#error ASN.1 DER requires MPI functionality #endif #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC) || defined(MKATJA)) && !defined(LTC_DER) - #error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled +#error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled #endif /* THREAD management */ @@ -401,8 +400,6 @@ #endif - - /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_custom.h,v $ */ /* $Revision: 1.73 $ */ /* $Date: 2007/05/12 14:37:41 $ */ diff --git a/libtomcrypt/headers/tomcrypt_hash.h b/libtomcrypt/headers/tomcrypt_hash.h index e4e84e4..7f791f6 100644 --- a/libtomcrypt/headers/tomcrypt_hash.h +++ b/libtomcrypt/headers/tomcrypt_hash.h @@ -5,10 +5,10 @@ struct algo_properties_st; int hash_is_valid(const struct algo_properties_st *hash); int hash_memory(const struct algo_properties_st *hash, - const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); -int hash_memory_multi(const struct algo_properties_st *hash, unsigned char *out, unsigned long *outlen, - const unsigned char *in, unsigned long inlen, ...); - -int hash_get_oid(const struct algo_properties_st *hash, oid_st* st); + const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen); +int hash_memory_multi(const struct algo_properties_st *hash, unsigned char *out, + unsigned long *outlen, const unsigned char *in, + unsigned long inlen, ...); +int hash_get_oid(const struct algo_properties_st *hash, oid_st * st); diff --git a/libtomcrypt/headers/tomcrypt_macros.h b/libtomcrypt/headers/tomcrypt_macros.h index 53bda9b..027dac8 100644 --- a/libtomcrypt/headers/tomcrypt_macros.h +++ b/libtomcrypt/headers/tomcrypt_macros.h @@ -1,19 +1,19 @@ /* fix for MSVC ...evil! */ #ifdef _MSC_VER - #define CONST64(n) n ## ui64 - typedef unsigned __int64 ulong64; +#define CONST64(n) n ## ui64 +typedef unsigned __int64 ulong64; #else - #define CONST64(n) n ## ULL - typedef unsigned long long ulong64; +#define CONST64(n) n ## ULL +typedef unsigned long long ulong64; #endif /* this is the "32-bit at least" data type * Re-define it to suit your platform but it must be at least 32-bits */ #if defined(__x86_64__) || (defined(__sparc__) && defined(__arch64__)) - typedef unsigned ulong32; +typedef unsigned ulong32; #else - typedef unsigned long ulong32; +typedef unsigned long ulong32; #endif /* ---- HELPER MACROS ---- */ @@ -96,7 +96,6 @@ asm __volatile__ ( \ #endif - /* x86_64 processor */ #if !defined(LTC_NO_BSWAP) && (defined(__GNUC__) && defined(__x86_64__)) @@ -129,7 +128,7 @@ asm __volatile__ ( \ #endif -#ifdef ENDIAN_32BITWORD +#ifdef ENDIAN_32BITWORD #define STORE32L(x, y) \ { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } @@ -190,7 +189,7 @@ asm __volatile__ ( \ (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \ (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); } -#ifdef ENDIAN_32BITWORD +#ifdef ENDIAN_32BITWORD #define STORE32H(x, y) \ { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } @@ -230,7 +229,6 @@ asm __volatile__ ( \ #define BSWAP(x) ( ((x>>24)&0x000000FFUL) | ((x<<24)&0xFF000000UL) | \ ((x>>8)&0x0000FF00UL) | ((x<<8)&0x00FF0000UL) ) - /* 32-bit Rotates */ #if defined(_MSC_VER) @@ -246,36 +244,32 @@ asm __volatile__ ( \ static inline unsigned ROL(unsigned word, int i) { - asm ("roll %%cl,%0" - :"=r" (word) - :"0" (word),"c" (i)); - return word; +asm("roll %%cl,%0":"=r"(word) +: "0"(word), "c"(i)); + return word; } static inline unsigned ROR(unsigned word, int i) { - asm ("rorl %%cl,%0" - :"=r" (word) - :"0" (word),"c" (i)); - return word; +asm("rorl %%cl,%0":"=r"(word) +: "0"(word), "c"(i)); + return word; } #ifndef LTC_NO_ROLC static inline unsigned ROLc(unsigned word, const int i) { - asm ("roll %2,%0" - :"=r" (word) - :"0" (word),"I" (i)); - return word; +asm("roll %2,%0":"=r"(word) +: "0"(word), "I"(i)); + return word; } static inline unsigned RORc(unsigned word, const int i) { - asm ("rorl %2,%0" - :"=r" (word) - :"0" (word),"I" (i)); - return word; +asm("rorl %2,%0":"=r"(word) +: "0"(word), "I"(i)); + return word; } #else @@ -289,36 +283,32 @@ static inline unsigned RORc(unsigned word, const int i) static inline unsigned ROL(unsigned word, int i) { - asm ("rotlw %0,%0,%2" - :"=r" (word) - :"0" (word),"r" (i)); - return word; +asm("rotlw %0,%0,%2":"=r"(word) +: "0"(word), "r"(i)); + return word; } static inline unsigned ROR(unsigned word, int i) { - asm ("rotlw %0,%0,%2" - :"=r" (word) - :"0" (word),"r" (32-i)); - return word; +asm("rotlw %0,%0,%2":"=r"(word) +: "0"(word), "r"(32 - i)); + return word; } #ifndef LTC_NO_ROLC static inline unsigned ROLc(unsigned word, const int i) { - asm ("rotlwi %0,%0,%2" - :"=r" (word) - :"0" (word),"I" (i)); - return word; +asm("rotlwi %0,%0,%2":"=r"(word) +: "0"(word), "I"(i)); + return word; } static inline unsigned RORc(unsigned word, const int i) { - asm ("rotrwi %0,%0,%2" - :"=r" (word) - :"0" (word),"I" (i)); - return word; +asm("rotrwi %0,%0,%2":"=r"(word) +: "0"(word), "I"(i)); + return word; } #else @@ -328,7 +318,6 @@ static inline unsigned RORc(unsigned word, const int i) #endif - #else /* rotates the hard way */ @@ -339,42 +328,37 @@ static inline unsigned RORc(unsigned word, const int i) #endif - /* 64-bit Rotates */ #if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__x86_64__) && !defined(LTC_NO_ASM) static inline unsigned long ROL64(unsigned long word, int i) { - asm("rolq %%cl,%0" - :"=r" (word) - :"0" (word),"c" (i)); - return word; +asm("rolq %%cl,%0":"=r"(word) +: "0"(word), "c"(i)); + return word; } static inline unsigned long ROR64(unsigned long word, int i) { - asm("rorq %%cl,%0" - :"=r" (word) - :"0" (word),"c" (i)); - return word; +asm("rorq %%cl,%0":"=r"(word) +: "0"(word), "c"(i)); + return word; } #ifndef LTC_NO_ROLC static inline unsigned long ROL64c(unsigned long word, const int i) { - asm("rolq %2,%0" - :"=r" (word) - :"0" (word),"J" (i)); - return word; +asm("rolq %2,%0":"=r"(word) +: "0"(word), "J"(i)); + return word; } static inline unsigned long ROR64c(unsigned long word, const int i) { - asm("rorq %2,%0" - :"=r" (word) - :"0" (word),"J" (i)); - return word; +asm("rorq %2,%0":"=r"(word) +: "0"(word), "J"(i)); + return word; } #else /* LTC_NO_ROLC */ @@ -405,19 +389,19 @@ static inline unsigned long ROR64c(unsigned long word, const int i) #endif #ifndef MAX - #define MAX(x, y) ( ((x)>(y))?(x):(y) ) +#define MAX(x, y) ( ((x)>(y))?(x):(y) ) #endif #ifndef MIN - #define MIN(x, y) ( ((x)<(y))?(x):(y) ) +#define MIN(x, y) ( ((x)<(y))?(x):(y) ) #endif /* extract a byte portably */ #ifdef _MSC_VER - #define byte(x, n) ((unsigned char)((x) >> (8 * (n)))) +#define byte(x, n) ((unsigned char)((x) >> (8 * (n)))) #else - #define byte(x, n) (((x) >> (8 * (n))) & 255) -#endif +#define byte(x, n) (((x) >> (8 * (n))) & 255) +#endif /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_macros.h,v $ */ /* $Revision: 1.15 $ */ diff --git a/libtomcrypt/headers/tomcrypt_math.h b/libtomcrypt/headers/tomcrypt_math.h index 6c0e6c5..e997429 100644 --- a/libtomcrypt/headers/tomcrypt_math.h +++ b/libtomcrypt/headers/tomcrypt_math.h @@ -9,5 +9,4 @@ #include <tommath.h> -typedef mp_int* mp_int_t; - +typedef mp_int *mp_int_t; diff --git a/libtomcrypt/headers/tomcrypt_misc.h b/libtomcrypt/headers/tomcrypt_misc.h index f5384ca..f525387 100644 --- a/libtomcrypt/headers/tomcrypt_misc.h +++ b/libtomcrypt/headers/tomcrypt_misc.h @@ -1,10 +1,10 @@ /* ---- LTC_BASE64 Routines ---- */ #ifdef LTC_BASE64 -int base64_encode(const unsigned char *in, unsigned long len, - unsigned char *out, unsigned long *outlen); +int base64_encode(const unsigned char *in, unsigned long len, + unsigned char *out, unsigned long *outlen); -int base64_decode(const unsigned char *in, unsigned long len, - unsigned char *out, unsigned long *outlen); +int base64_decode(const unsigned char *in, unsigned long len, + unsigned char *out, unsigned long *outlen); #endif /* ---- MEM routines ---- */ diff --git a/libtomcrypt/headers/tomcrypt_pk.h b/libtomcrypt/headers/tomcrypt_pk.h index 7334880..f544e44 100644 --- a/libtomcrypt/headers/tomcrypt_pk.h +++ b/libtomcrypt/headers/tomcrypt_pk.h @@ -3,23 +3,23 @@ struct algo_properties_st; enum { - PK_PUBLIC=0, - PK_PRIVATE=1 + PK_PUBLIC = 0, + PK_PRIVATE = 1 }; enum { - PKA_RSA, - PKA_DSA + PKA_RSA, + PKA_DSA }; typedef struct Oid { - unsigned long OID[16]; + unsigned long OID[16]; /** Length of DER encoding */ - unsigned long OIDlen; + unsigned long OIDlen; } oid_st; -int pk_get_oid(int pk, oid_st *st); -int rand_prime(mp_int *N, long len); +int pk_get_oid(int pk, oid_st * st); +int rand_prime(mp_int * N, long len); /* ---- RSA ---- */ #ifdef LTC_MRSA @@ -31,32 +31,32 @@ int rand_prime(mp_int *N, long len); /** RSA LTC_PKCS style key */ typedef struct Rsa_key { /** Type of key, PK_PRIVATE or PK_PUBLIC */ - int type; + int type; /** The public exponent */ - mp_int e; + mp_int e; /** The private exponent */ - mp_int d; + mp_int d; /** The modulus */ - mp_int N; + mp_int N; /** The p factor of N */ - mp_int p; + mp_int p; /** The q factor of N */ - mp_int q; + mp_int q; /** The 1/q mod p CRT param */ - mp_int qP; + mp_int qP; /** The d mod (p - 1) CRT param */ - mp_int dP; + mp_int dP; /** The d mod (q - 1) CRT param */ - mp_int dQ; + mp_int dQ; } rsa_key; -int rsa_make_key(int size, long e, rsa_key *key); +int rsa_make_key(int size, long e, rsa_key * key); -int rsa_exptmod(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen, int which, - rsa_key *key); +int rsa_exptmod(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, int which, + rsa_key * key); -void rsa_free(rsa_key *key); +void rsa_free(rsa_key * key); /* These use LTC_PKCS #1 v2.0 padding */ #define rsa_encrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash, _key) \ @@ -72,35 +72,36 @@ void rsa_free(rsa_key *key); rsa_verify_hash_ex(_sig, _siglen, _hash, _hashlen, LTC_LTC_PKCS_1_PSS, _hash_algo, _saltlen, _stat, _key) /* These can be switched between LTC_PKCS #1 v2.x and LTC_PKCS #1 v1.5 paddings */ -int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen, - const unsigned char *lparam, unsigned long lparamlen, - const struct algo_properties_st *hash, int padding, rsa_key *key); - -int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen, - const unsigned char *lparam, unsigned long lparamlen, - const struct algo_properties_st *hash, int padding, - int *stat, rsa_key *key); - -int rsa_sign_hash_ex(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen, - int padding, - const struct algo_properties_st *hash, unsigned long saltlen, - rsa_key *key); - -int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen, - const unsigned char *hash, unsigned long hashlen, - int padding, - const struct algo_properties_st *hash_algo, unsigned long saltlen, - int *stat, rsa_key *key); +int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, + const unsigned char *lparam, unsigned long lparamlen, + const struct algo_properties_st *hash, int padding, + rsa_key * key); + +int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, + const unsigned char *lparam, unsigned long lparamlen, + const struct algo_properties_st *hash, int padding, + int *stat, rsa_key * key); + +int rsa_sign_hash_ex(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, + int padding, + const struct algo_properties_st *hash, + unsigned long saltlen, rsa_key * key); + +int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen, + const unsigned char *hash, unsigned long hashlen, + int padding, + const struct algo_properties_st *hash_algo, + unsigned long saltlen, int *stat, rsa_key * key); /* LTC_PKCS #1 import/export */ -int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key); -int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key); - -#endif +int rsa_export(unsigned char *out, unsigned long *outlen, int type, + rsa_key * key); +int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key * key); +#endif #ifdef LTC_MDSA @@ -113,97 +114,95 @@ int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key); /** DSA key structure */ typedef struct { /** The key type, PK_PRIVATE or PK_PUBLIC */ - int type; + int type; /** The order of the sub-group used in octets */ - int qord; + int qord; /** The generator */ - mp_int g; + mp_int g; /** The prime used to generate the sub-group */ - mp_int q; + mp_int q; /** The large prime that generats the field the contains the sub-group */ - mp_int p; + mp_int p; /** The private key */ - mp_int x; + mp_int x; /** The public key */ - mp_int y; + mp_int y; } dsa_key; -int dsa_make_key(int group_size, int modulus_size, dsa_key *key); -void dsa_free(dsa_key *key); - -int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen, - mp_int_t r, mp_int_t s, - dsa_key *key); - -int dsa_sign_hash(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen, - dsa_key *key); - -int dsa_verify_hash_raw( mp_int_t r, mp_int_t s, - const unsigned char *hash, unsigned long hashlen, - int *stat, dsa_key *key); - -int dsa_verify_hash(const unsigned char *sig, unsigned long siglen, - const unsigned char *hash, unsigned long hashlen, - int *stat, dsa_key *key); - -int dsa_encrypt_key(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen, - int hash, dsa_key *key); - -int dsa_decrypt_key(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen, - dsa_key *key); - -int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key); -int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key); -int dsa_verify_key(dsa_key *key, int *stat); - -int dsa_shared_secret(void *private_key, mp_int_t base, - dsa_key *public_key, - unsigned char *out, unsigned long *outlen); +int dsa_make_key(int group_size, int modulus_size, dsa_key * key); +void dsa_free(dsa_key * key); + +int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen, + mp_int_t r, mp_int_t s, dsa_key * key); + +int dsa_sign_hash(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, dsa_key * key); + +int dsa_verify_hash_raw(mp_int_t r, mp_int_t s, + const unsigned char *hash, unsigned long hashlen, + int *stat, dsa_key * key); + +int dsa_verify_hash(const unsigned char *sig, unsigned long siglen, + const unsigned char *hash, unsigned long hashlen, + int *stat, dsa_key * key); + +int dsa_encrypt_key(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, + int hash, dsa_key * key); + +int dsa_decrypt_key(const unsigned char *in, unsigned long inlen, + unsigned char *out, unsigned long *outlen, dsa_key * key); + +int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key * key); +int dsa_export(unsigned char *out, unsigned long *outlen, int type, + dsa_key * key); +int dsa_verify_key(dsa_key * key, int *stat); + +int dsa_shared_secret(void *private_key, mp_int_t base, + dsa_key * public_key, + unsigned char *out, unsigned long *outlen); #endif #ifdef LTC_DER /* DER handling */ enum { - LTC_ASN1_EOL, - LTC_ASN1_BOOLEAN, - LTC_ASN1_INTEGER, - LTC_ASN1_SHORT_INTEGER, - LTC_ASN1_BIT_STRING, - LTC_ASN1_OCTET_STRING, - LTC_ASN1_NULL, - LTC_ASN1_OBJECT_IDENTIFIER, - LTC_ASN1_IA5_STRING, - LTC_ASN1_PRINTABLE_STRING, - LTC_ASN1_UTF8_STRING, - LTC_ASN1_UTCTIME, - LTC_ASN1_CHOICE, - LTC_ASN1_SEQUENCE, - LTC_ASN1_SET, - LTC_ASN1_SETOF + LTC_ASN1_EOL, + LTC_ASN1_BOOLEAN, + LTC_ASN1_INTEGER, + LTC_ASN1_SHORT_INTEGER, + LTC_ASN1_BIT_STRING, + LTC_ASN1_OCTET_STRING, + LTC_ASN1_NULL, + LTC_ASN1_OBJECT_IDENTIFIER, + LTC_ASN1_IA5_STRING, + LTC_ASN1_PRINTABLE_STRING, + LTC_ASN1_UTF8_STRING, + LTC_ASN1_UTCTIME, + LTC_ASN1_CHOICE, + LTC_ASN1_SEQUENCE, + LTC_ASN1_SET, + LTC_ASN1_SETOF }; /** A LTC ASN.1 list type */ typedef struct ltc_asn1_list_ { /** The LTC ASN.1 enumerated type identifier */ - int type; + int type; /** The data to encode or place for decoding */ - void *data; + void *data; /** The size of the input or resulting output */ - unsigned long size; + unsigned long size; /** The used flag, this is used by the CHOICE ASN.1 type to indicate which choice was made */ - int used; + int used; /** prev/next entry in the list */ - struct ltc_asn1_list_ *prev, *next, *child, *parent; + struct ltc_asn1_list_ *prev, *next, *child, *parent; } ltc_asn1_list; #define LTC_SET_ASN1(list, index, Type, Data, Size) \ @@ -217,140 +216,155 @@ typedef struct ltc_asn1_list_ { } while (0); /* SEQUENCE */ -int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen, - unsigned char *out, unsigned long *outlen, int type_of); - -#define der_encode_sequence(list, inlen, out, outlen) der_encode_sequence_ex(list, inlen, out, outlen, LTC_ASN1_SEQUENCE) +int der_encode_sequence_ex(ltc_asn1_list * list, unsigned long inlen, + unsigned char *out, unsigned long *outlen, + int type_of); -int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen, - ltc_asn1_list *list, unsigned long outlen, int ordered); +#define der_encode_sequence(list, inlen, out, outlen) der_encode_sequence_ex(list, inlen, out, outlen, LTC_ASN1_SEQUENCE) + +int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen, + ltc_asn1_list * list, unsigned long outlen, + int ordered); #define der_decode_sequence(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 1) -int der_length_sequence(ltc_asn1_list *list, unsigned long inlen, - unsigned long *outlen); +int der_length_sequence(ltc_asn1_list * list, unsigned long inlen, + unsigned long *outlen); /* SUBJECT PUBLIC KEY INFO */ -int der_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen, - unsigned int algorithm, void* public_key, unsigned long public_key_len, - unsigned long parameters_type, void* parameters, unsigned long parameters_len); - -int der_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen, - unsigned int algorithm, void* public_key, unsigned long* public_key_len, - unsigned long parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len); +int der_encode_subject_public_key_info(unsigned char *out, + unsigned long *outlen, + unsigned int algorithm, void *public_key, + unsigned long public_key_len, + unsigned long parameters_type, + void *parameters, + unsigned long parameters_len); + +int der_decode_subject_public_key_info(const unsigned char *in, + unsigned long inlen, + unsigned int algorithm, void *public_key, + unsigned long *public_key_len, + unsigned long parameters_type, + ltc_asn1_list * parameters, + unsigned long parameters_len); /* SET */ #define der_decode_set(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 0) #define der_length_set der_length_sequence -int der_encode_set(ltc_asn1_list *list, unsigned long inlen, - unsigned char *out, unsigned long *outlen); +int der_encode_set(ltc_asn1_list * list, unsigned long inlen, + unsigned char *out, unsigned long *outlen); + +int der_encode_setof(ltc_asn1_list * list, unsigned long inlen, + unsigned char *out, unsigned long *outlen); -int der_encode_setof(ltc_asn1_list *list, unsigned long inlen, - unsigned char *out, unsigned long *outlen); - /* VA list handy helpers with triplets of <type, size, data> */ int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...); -int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...); +int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, + ...); /* FLEXI DECODER handle unknown list decoder */ -int der_decode_sequence_flexi(const unsigned char *in, unsigned long *inlen, ltc_asn1_list **out); -void der_free_sequence_flexi(ltc_asn1_list *list); -void der_sequence_free(ltc_asn1_list *in); +int der_decode_sequence_flexi(const unsigned char *in, unsigned long *inlen, + ltc_asn1_list ** out); +void der_free_sequence_flexi(ltc_asn1_list * list); +void der_sequence_free(ltc_asn1_list * in); /* BOOLEAN */ int der_length_boolean(unsigned long *outlen); -int der_encode_boolean(int in, - unsigned char *out, unsigned long *outlen); -int der_decode_boolean(const unsigned char *in, unsigned long inlen, - int *out); +int der_encode_boolean(int in, unsigned char *out, unsigned long *outlen); +int der_decode_boolean(const unsigned char *in, unsigned long inlen, int *out); /* INTEGER */ int der_encode_integer(mp_int_t num, unsigned char *out, unsigned long *outlen); -int der_decode_integer(const unsigned char *in, unsigned long inlen, mp_int_t num); +int der_decode_integer(const unsigned char *in, unsigned long inlen, + mp_int_t num); int der_length_integer(mp_int_t num, unsigned long *len); /* INTEGER -- handy for 0..2^32-1 values */ -int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num); -int der_encode_short_integer(unsigned long num, unsigned char *out, unsigned long *outlen); +int der_decode_short_integer(const unsigned char *in, unsigned long inlen, + unsigned long *num); +int der_encode_short_integer(unsigned long num, unsigned char *out, + unsigned long *outlen); int der_length_short_integer(unsigned long num, unsigned long *outlen); /* BIT STRING */ int der_encode_bit_string(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); + unsigned char *out, unsigned long *outlen); int der_decode_bit_string(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); + unsigned char *out, unsigned long *outlen); int der_length_bit_string(unsigned long nbits, unsigned long *outlen); /* OCTET STRING */ int der_encode_octet_string(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); + unsigned char *out, unsigned long *outlen); int der_decode_octet_string(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); + unsigned char *out, unsigned long *outlen); int der_length_octet_string(unsigned long noctets, unsigned long *outlen); /* OBJECT IDENTIFIER */ -int der_encode_object_identifier(unsigned long *words, unsigned long nwords, - unsigned char *out, unsigned long *outlen); -int der_decode_object_identifier(const unsigned char *in, unsigned long inlen, - unsigned long *words, unsigned long *outlen); -int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen); +int der_encode_object_identifier(unsigned long *words, unsigned long nwords, + unsigned char *out, unsigned long *outlen); +int der_decode_object_identifier(const unsigned char *in, unsigned long inlen, + unsigned long *words, unsigned long *outlen); +int der_length_object_identifier(unsigned long *words, unsigned long nwords, + unsigned long *outlen); unsigned long der_object_identifier_bits(unsigned long x); /* IA5 STRING */ int der_encode_ia5_string(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); + unsigned char *out, unsigned long *outlen); int der_decode_ia5_string(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); -int der_length_ia5_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen); + unsigned char *out, unsigned long *outlen); +int der_length_ia5_string(const unsigned char *octets, unsigned long noctets, + unsigned long *outlen); int der_ia5_char_encode(int c); int der_ia5_value_decode(int v); /* Printable STRING */ int der_encode_printable_string(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); + unsigned char *out, unsigned long *outlen); int der_decode_printable_string(const unsigned char *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); -int der_length_printable_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen); + unsigned char *out, unsigned long *outlen); +int der_length_printable_string(const unsigned char *octets, + unsigned long noctets, unsigned long *outlen); int der_printable_char_encode(int c); int der_printable_value_decode(int v); /* UTF-8 */ -int der_encode_utf8_string(const wchar_t *in, unsigned long inlen, - unsigned char *out, unsigned long *outlen); +int der_encode_utf8_string(const wchar_t * in, unsigned long inlen, + unsigned char *out, unsigned long *outlen); -int der_decode_utf8_string(const unsigned char *in, unsigned long inlen, - wchar_t *out, unsigned long *outlen); +int der_decode_utf8_string(const unsigned char *in, unsigned long inlen, + wchar_t * out, unsigned long *outlen); unsigned long der_utf8_charsize(const wchar_t c); -int der_length_utf8_string(const wchar_t *in, unsigned long noctets, unsigned long *outlen); - +int der_length_utf8_string(const wchar_t * in, unsigned long noctets, + unsigned long *outlen); /* CHOICE */ -int der_decode_choice(const unsigned char *in, unsigned long *inlen, - ltc_asn1_list *list, unsigned long outlen); +int der_decode_choice(const unsigned char *in, unsigned long *inlen, + ltc_asn1_list * list, unsigned long outlen); /* UTCTime */ typedef struct { - unsigned YY, /* year */ - MM, /* month */ - DD, /* day */ - hh, /* hour */ - mm, /* minute */ - ss, /* second */ - off_dir, /* timezone offset direction 0 == +, 1 == - */ - off_hh, /* timezone offset hours */ - off_mm; /* timezone offset minutes */ + unsigned YY, /* year */ + MM, /* month */ + DD, /* day */ + hh, /* hour */ + mm, /* minute */ + ss, /* second */ + off_dir, /* timezone offset direction 0 == +, 1 == - */ + off_hh, /* timezone offset hours */ + off_mm; /* timezone offset minutes */ } ltc_utctime; -int der_encode_utctime(ltc_utctime *utctime, - unsigned char *out, unsigned long *outlen); +int der_encode_utctime(ltc_utctime * utctime, + unsigned char *out, unsigned long *outlen); int der_decode_utctime(const unsigned char *in, unsigned long *inlen, - ltc_utctime *out); - -int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen); + ltc_utctime * out); +int der_length_utctime(ltc_utctime * utctime, unsigned long *outlen); #endif diff --git a/libtomcrypt/headers/tomcrypt_pkcs.h b/libtomcrypt/headers/tomcrypt_pkcs.h index be0d7f6..f282b0f 100644 --- a/libtomcrypt/headers/tomcrypt_pkcs.h +++ b/libtomcrypt/headers/tomcrypt_pkcs.h @@ -5,63 +5,61 @@ struct algo_properties_st; -enum ltc_pkcs_1_v1_5_blocks -{ - LTC_LTC_PKCS_1_EMSA = 1, /* Block type 1 (LTC_PKCS #1 v1.5 signature padding) */ - LTC_LTC_PKCS_1_EME = 2 /* Block type 2 (LTC_PKCS #1 v1.5 encryption padding) */ +enum ltc_pkcs_1_v1_5_blocks { + LTC_LTC_PKCS_1_EMSA = 1, /* Block type 1 (LTC_PKCS #1 v1.5 signature padding) */ + LTC_LTC_PKCS_1_EME = 2 /* Block type 2 (LTC_PKCS #1 v1.5 encryption padding) */ }; -enum ltc_pkcs_1_paddings -{ - LTC_LTC_PKCS_1_V1_5 = 1, /* LTC_PKCS #1 v1.5 padding (\sa ltc_pkcs_1_v1_5_blocks) */ - LTC_LTC_PKCS_1_OAEP = 2, /* LTC_PKCS #1 v2.0 encryption padding */ - LTC_LTC_PKCS_1_PSS = 3 /* LTC_PKCS #1 v2.1 signature padding */ +enum ltc_pkcs_1_paddings { + LTC_LTC_PKCS_1_V1_5 = 1, /* LTC_PKCS #1 v1.5 padding (\sa ltc_pkcs_1_v1_5_blocks) */ + LTC_LTC_PKCS_1_OAEP = 2, /* LTC_PKCS #1 v2.0 encryption padding */ + LTC_LTC_PKCS_1_PSS = 3 /* LTC_PKCS #1 v2.1 signature padding */ }; int pkcs_1_mgf1(const struct algo_properties_st *hash, - const unsigned char *seed, unsigned long seedlen, - unsigned char *mask, unsigned long masklen); + const unsigned char *seed, unsigned long seedlen, + unsigned char *mask, unsigned long masklen); int pkcs_1_i2osp(void *n, unsigned long modulus_len, unsigned char *out); int pkcs_1_os2ip(void *n, unsigned char *in, unsigned long inlen); /* *** v1.5 padding */ -int pkcs_1_v1_5_encode(const unsigned char *msg, - unsigned long msglen, - int block_type, - unsigned long modulus_bitlen, - unsigned char *out, - unsigned long *outlen); +int pkcs_1_v1_5_encode(const unsigned char *msg, + unsigned long msglen, + int block_type, + unsigned long modulus_bitlen, + unsigned char *out, unsigned long *outlen); -int pkcs_1_v1_5_decode(const unsigned char *msg, - unsigned long msglen, - int block_type, - unsigned long modulus_bitlen, - unsigned char *out, - unsigned long *outlen, - int *is_valid); +int pkcs_1_v1_5_decode(const unsigned char *msg, + unsigned long msglen, + int block_type, + unsigned long modulus_bitlen, + unsigned char *out, + unsigned long *outlen, int *is_valid); /* *** v2.1 padding */ -int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, - const unsigned char *lparam, unsigned long lparamlen, - unsigned long modulus_bitlen, const struct algo_properties_st *hash, - unsigned char *out, unsigned long *outlen); +int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, + const unsigned char *lparam, unsigned long lparamlen, + unsigned long modulus_bitlen, + const struct algo_properties_st *hash, + unsigned char *out, unsigned long *outlen); -int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen, - const unsigned char *lparam, unsigned long lparamlen, - unsigned long modulus_bitlen, const struct algo_properties_st *hash, - unsigned char *out, unsigned long *outlen, - int *res); +int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen, + const unsigned char *lparam, unsigned long lparamlen, + unsigned long modulus_bitlen, + const struct algo_properties_st *hash, + unsigned char *out, unsigned long *outlen, int *res); int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen, - unsigned long saltlen, const struct algo_properties_st *hash, - unsigned long modulus_bitlen, - unsigned char *out, unsigned long *outlen); + unsigned long saltlen, + const struct algo_properties_st *hash, + unsigned long modulus_bitlen, unsigned char *out, + unsigned long *outlen); int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen, - const unsigned char *sig, unsigned long siglen, - unsigned long saltlen, const struct algo_properties_st *hash, - unsigned long modulus_bitlen, int *res); + const unsigned char *sig, unsigned long siglen, + unsigned long saltlen, + const struct algo_properties_st *hash, + unsigned long modulus_bitlen, int *res); #endif /* LTC_PKCS_1 */ - diff --git a/libtomcrypt/headers/tomcrypt_prng.h b/libtomcrypt/headers/tomcrypt_prng.h index 26bf711..a3fe429 100644 --- a/libtomcrypt/headers/tomcrypt_prng.h +++ b/libtomcrypt/headers/tomcrypt_prng.h @@ -1,72 +1,79 @@ /* ---- PRNG Stuff ---- */ typedef union Prng_state { - char dummy[1]; + char dummy[1]; } prng_state; /** PRNG descriptor */ extern struct ltc_prng_descriptor { /** Name of the PRNG */ - char *name; + char *name; /** size in bytes of exported state */ - int export_size; + int export_size; /** Start a PRNG state @param prng [out] The state to initialize @return CRYPT_OK if successful */ - int (*start)(prng_state *prng); + int (*start) (prng_state * prng); /** Add entropy to the PRNG @param in The entropy @param inlen Length of the entropy (octets)\ @param prng The PRNG state @return CRYPT_OK if successful */ - int (*add_entropy)(const unsigned char *in, unsigned long inlen, prng_state *prng); + int (*add_entropy) (const unsigned char *in, unsigned long inlen, + prng_state * prng); /** Ready a PRNG state to read from @param prng The PRNG state to ready @return CRYPT_OK if successful */ - int (*ready)(prng_state *prng); + int (*ready) (prng_state * prng); /** Read from the PRNG @param out [out] Where to store the data @param outlen Length of data desired (octets) @param prng The PRNG state to read from @return Number of octets read */ - unsigned long (*read)(unsigned char *out, unsigned long outlen, prng_state *prng); + unsigned long (*read) (unsigned char *out, unsigned long outlen, + prng_state * prng); /** Terminate a PRNG state @param prng The PRNG state to terminate @return CRYPT_OK if successful */ - int (*done)(prng_state *prng); + int (*done) (prng_state * prng); /** Export a PRNG state @param out [out] The destination for the state @param outlen [in/out] The max size and resulting size of the PRNG state @param prng The PRNG to export @return CRYPT_OK if successful */ - int (*pexport)(unsigned char *out, unsigned long *outlen, prng_state *prng); + int (*pexport) (unsigned char *out, unsigned long *outlen, + prng_state * prng); /** Import a PRNG state @param in The data to import @param inlen The length of the data to import (octets) @param prng The PRNG to initialize/import @return CRYPT_OK if successful */ - int (*pimport)(const unsigned char *in, unsigned long inlen, prng_state *prng); + int (*pimport) (const unsigned char *in, unsigned long inlen, + prng_state * prng); /** Self-test the PRNG @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled */ - int (*test)(void); + int (*test) (void); } prng_descriptor[]; -int linux_start(prng_state *prng); -int linux_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng); -int linux_ready(prng_state *prng); -unsigned long linux_read(unsigned char *out, unsigned long outlen, prng_state *prng); -int linux_done(prng_state *prng); -int linux_export(unsigned char *out, unsigned long *outlen, prng_state *prng); -int linux_import(const unsigned char *in, unsigned long inlen, prng_state *prng); -int linux_test(void); +int linux_start(prng_state * prng); +int linux_add_entropy(const unsigned char *in, unsigned long inlen, + prng_state * prng); +int linux_ready(prng_state * prng); +unsigned long linux_read(unsigned char *out, unsigned long outlen, + prng_state * prng); +int linux_done(prng_state * prng); +int linux_export(unsigned char *out, unsigned long *outlen, prng_state * prng); +int linux_import(const unsigned char *in, unsigned long inlen, + prng_state * prng); +int linux_test(void); extern const struct ltc_prng_descriptor linux_desc; |