manually fix the remaining leading _'s

This commit is contained in:
Steffen Jaeckel 2020-07-14 19:02:48 +02:00
parent 373974edee
commit c5d7bfb2cc
41 changed files with 475 additions and 477 deletions

View File

@ -17,7 +17,7 @@
Larry Bugbee, February 2013
*/
static void _print_line(const char* cmd, const char* desc)
static void s_print_line(const char* cmd, const char* desc)
{
printf(" %-16s - %s\n", cmd, desc);
}
@ -48,10 +48,10 @@ int main(int argc, char **argv)
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
char* base = strdup(basename(argv[0]));
printf("Usage: %s [-a] [-s name]\n\n", base);
_print_line("<no argument>", "The old behavior of the demo");
_print_line("-a", "Only lists all constants");
_print_line("-s name", "List a single constant given as argument");
_print_line("-h", "The help you're looking at");
s_print_line("<no argument>", "The old behavior of the demo");
s_print_line("-a", "Only lists all constants");
s_print_line("-s name", "List a single constant given as argument");
s_print_line("-h", "The help you're looking at");
free(base);
} else if (strcmp(argv[1], "-a") == 0) {
char *names_list;

View File

@ -24,11 +24,11 @@
#endif
/* thanks http://stackoverflow.com/a/8198009 */
#define _base(x) ((x >= '0' && x <= '9') ? '0' : \
#define s_base(x) ((x >= '0' && x <= '9') ? '0' : \
(x >= 'a' && x <= 'f') ? 'a' - 10 : \
(x >= 'A' && x <= 'F') ? 'A' - 10 : \
'\255')
#define HEXOF(x) (x - _base(x))
#define HEXOF(x) (x - s_base(x))
static char* hashsum;

View File

@ -166,7 +166,7 @@ void dump_bytes(unsigned char *in, unsigned long len)
* Output: number of bytes after padding resp. after unpadding
* Side Effects: none
*/
static size_t _pkcs7_pad(union paddable *buf, size_t nb, int block_length,
static size_t s_pkcs7_pad(union paddable *buf, size_t nb, int block_length,
int is_padding)
{
unsigned long length;
@ -224,7 +224,7 @@ int do_crypt(FILE *infd, FILE *outfd, unsigned char *key, unsigned char *iv,
/* We're encrypting, so pad first (if at EOF) and then
crypt */
if(feof(infd))
nb = _pkcs7_pad(&inbuf, nb,
nb = s_pkcs7_pad(&inbuf, nb,
aes_desc.block_length, 1);
ret = cbc_encrypt(inbuf.pad, outbuf.pad, nb, &cbc);
@ -239,7 +239,7 @@ int do_crypt(FILE *infd, FILE *outfd, unsigned char *key, unsigned char *iv,
return ret;
if(feof(infd))
nb = _pkcs7_pad(&outbuf, nb,
nb = s_pkcs7_pad(&outbuf, nb,
aes_desc.block_length, 0);
if(nb == 0)
/* The file didn't decrypt correctly */

View File

@ -15,7 +15,7 @@
like Python - Larry Bugbee, February 2013
*/
static void _print_line(const char* cmd, const char* desc)
static void s_print_line(const char* cmd, const char* desc)
{
printf(" %-16s - %s\n", cmd, desc);
}
@ -44,10 +44,10 @@ int main(int argc, char **argv)
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
char* base = strdup(basename(argv[0]));
printf("Usage: %s [-a] [-s name]\n\n", base);
_print_line("<no argument>", "The old behavior of the demo");
_print_line("-a", "Only lists all sizes");
_print_line("-s name", "List a single size given as argument");
_print_line("-h", "The help you're looking at");
s_print_line("<no argument>", "The old behavior of the demo");
s_print_line("-a", "Only lists all sizes");
s_print_line("-s name", "List a single size given as argument");
s_print_line("-h", "The help you're looking at");
free(base);
} else if (strcmp(argv[1], "-a") == 0) {
char *sizes_list;

View File

@ -560,7 +560,7 @@ of this array has the following (partial) format (See Section \ref{sec:cipherdes
\begin{small}
\begin{verbatim}
struct _cipher_descriptor {
struct ltc_cipher_descriptor {
/** name of cipher */
char *name;
@ -745,14 +745,14 @@ A good safety would be to check the return value of \textit{find\_cipher()} befo
to use a cipher with the descriptor table you must register it first using:
\index{register\_cipher()}
\begin{verbatim}
int register_cipher(const struct _cipher_descriptor *cipher);
int register_cipher(const struct ltc_cipher_descriptor *cipher);
\end{verbatim}
Which accepts a pointer to a descriptor and returns the index into the global descriptor table. If an error occurs such
as there is no more room (it can have 32 ciphers at most) it will return {\bf{-1}}. If you try to add the same cipher more
than once it will just return the index of the first copy. To remove a cipher call:
\index{unregister\_cipher()}
\begin{verbatim}
int unregister_cipher(const struct _cipher_descriptor *cipher);
int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
\end{verbatim}
Which returns {\bf CRYPT\_OK} if it removes the cipher, otherwise it returns {\bf CRYPT\_ERROR}.
\begin{small}
@ -2594,7 +2594,7 @@ int main(void)
Like the set of ciphers, the set of hashes have descriptors as well. They are stored in an array called \textit{hash\_descriptor} and
are defined by:
\begin{verbatim}
struct _hash_descriptor {
struct ltc_hash_descriptor {
char *name;
unsigned long hashsize; /* digest output size in bytes */
@ -2753,9 +2753,9 @@ Similar to the cipher descriptor table you must register your hash algorithms be
work exactly like those of the cipher registration code. The functions are:
\index{register\_hash()} \index{unregister\_hash()}
\begin{verbatim}
int register_hash(const struct _hash_descriptor *hash);
int register_hash(const struct ltc_hash_descriptor *hash);
int unregister_hash(const struct _hash_descriptor *hash);
int unregister_hash(const struct ltc_hash_descriptor *hash);
\end{verbatim}
The following hashes are provided as of this release within the LibTomCrypt library:
@ -3824,7 +3824,7 @@ int main(void)
PRNGs have descriptors that allow plugin driven functions to be created using PRNGs. The plugin descriptors are stored in the structure \textit{prng\_descriptor}. The
format of an element is:
\begin{verbatim}
struct _prng_descriptor {
struct ltc_prng_descriptor {
char *name;
int export_size; /* size in bytes of exported state */
@ -3860,8 +3860,8 @@ Just like the ciphers and hashes, you must register your prng before you can use
They are the following:
\index{register\_prng()} \index{unregister\_prng()}
\begin{verbatim}
int register_prng(const struct _prng_descriptor *prng);
int unregister_prng(const struct _prng_descriptor *prng);
int register_prng(const struct ltc_prng_descriptor *prng);
int unregister_prng(const struct ltc_prng_descriptor *prng);
\end{verbatim}
The register function will register the PRNG, and return the index into the table where it was placed (or -1 for error). It will avoid registering the same

View File

@ -275,7 +275,7 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
static int s_rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#else
int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#endif
@ -443,7 +443,7 @@ int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *ske
#ifdef LTC_CLEAN_STACK
int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _rijndael_ecb_encrypt(pt, ct, skey);
int err = s_rijndael_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
return err;
}
@ -459,7 +459,7 @@ int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *ske
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
static int s_rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#else
int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#endif
@ -628,7 +628,7 @@ int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *ske
#ifdef LTC_CLEAN_STACK
int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _rijndael_ecb_decrypt(ct, pt, skey);
int err = s_rijndael_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
return err;
}

View File

@ -876,7 +876,7 @@ static const ulong32 rc[] = {
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
static int s_anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#else
int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#endif
@ -1013,7 +1013,7 @@ int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
int err;
err = _anubis_setup(key, keylen, num_rounds, skey);
err = s_anubis_setup(key, keylen, num_rounds, skey);
burn_stack(sizeof(int) * 5 + sizeof(ulong32) * (MAX_N + MAX_N + 5));
return err;
}

View File

@ -472,7 +472,7 @@ int blowfish_setup_with_data(const unsigned char *key, int keylen,
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
static int s_blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#else
int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#endif
@ -499,7 +499,7 @@ int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
#ifdef LTC_CLEAN_STACK
int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _blowfish_ecb_encrypt(pt, ct, skey);
int err = s_blowfish_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
return err;
}
@ -513,7 +513,7 @@ int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
static int s_blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#else
int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#endif
@ -560,7 +560,7 @@ int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symme
#ifdef LTC_CLEAN_STACK
int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _blowfish_ecb_decrypt(ct, pt, skey);
int err = s_blowfish_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
return err;
}

View File

@ -398,7 +398,7 @@ static const ulong32 S8[256] = {
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
static int s_cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#else
int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#endif
@ -485,7 +485,7 @@ int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
int z;
z = _cast5_setup(key, keylen, num_rounds, skey);
z = s_cast5_setup(key, keylen, num_rounds, skey);
burn_stack(sizeof(ulong32)*8 + 16 + sizeof(int)*2);
return z;
}
@ -522,7 +522,7 @@ LTC_INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
@param skey The key as scheduled
*/
#ifdef LTC_CLEAN_STACK
static int _cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
static int s_cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#else
int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#endif
@ -562,7 +562,7 @@ int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetri
#ifdef LTC_CLEAN_STACK
int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err =_cast5_ecb_encrypt(pt,ct,skey);
int err = s_cast5_ecb_encrypt(pt,ct,skey);
burn_stack(sizeof(ulong32)*3);
return err;
}
@ -575,7 +575,7 @@ int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetri
@param skey The key as scheduled
*/
#ifdef LTC_CLEAN_STACK
static int _cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
static int s_cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#else
int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#endif
@ -615,7 +615,7 @@ int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetri
#ifdef LTC_CLEAN_STACK
int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _cast5_ecb_decrypt(ct,pt,skey);
int err = s_cast5_ecb_decrypt(ct,pt,skey);
burn_stack(sizeof(ulong32)*3);
return err;
}

View File

@ -1293,7 +1293,7 @@ static const ulong64 des_fp[8][256] = {
static void cookey(const ulong32 *raw1, ulong32 *keyout);
#ifdef LTC_CLEAN_STACK
static void _deskey(const unsigned char *key, short edf, ulong32 *keyout)
static void s_deskey(const unsigned char *key, short edf, ulong32 *keyout)
#else
static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
#endif
@ -1347,13 +1347,13 @@ static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
#ifdef LTC_CLEAN_STACK
static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
{
_deskey(key, edf, keyout);
s_deskey(key, edf, keyout);
burn_stack(sizeof(int)*5 + sizeof(ulong32)*32 + sizeof(unsigned char)*112);
}
#endif
#ifdef LTC_CLEAN_STACK
static void _cookey(const ulong32 *raw1, ulong32 *keyout)
static void s_cookey(const ulong32 *raw1, ulong32 *keyout)
#else
static void cookey(const ulong32 *raw1, ulong32 *keyout)
#endif
@ -1383,7 +1383,7 @@ static void cookey(const ulong32 *raw1, ulong32 *keyout)
#ifdef LTC_CLEAN_STACK
static void cookey(const ulong32 *raw1, ulong32 *keyout)
{
_cookey(raw1, keyout);
s_cookey(raw1, keyout);
burn_stack(sizeof(ulong32 *) * 2 + sizeof(ulong32)*32 + sizeof(int));
}
#endif
@ -1391,7 +1391,7 @@ static void cookey(const ulong32 *raw1, ulong32 *keyout)
#ifndef LTC_CLEAN_STACK
static void desfunc(ulong32 *block, const ulong32 *keys)
#else
static void _desfunc(ulong32 *block, const ulong32 *keys)
static void s_desfunc(ulong32 *block, const ulong32 *keys)
#endif
{
ulong32 work, right, leftt;
@ -1505,7 +1505,7 @@ static void _desfunc(ulong32 *block, const ulong32 *keys)
#ifdef LTC_CLEAN_STACK
static void desfunc(ulong32 *block, const ulong32 *keys)
{
_desfunc(block, keys);
s_desfunc(block, keys);
burn_stack(sizeof(ulong32) * 4 + sizeof(int));
}
#endif

View File

@ -49,7 +49,7 @@ typedef unsigned short int ushort16;
#define STORE16(x,y) { (y)[0] = (unsigned char)(((x)>>8)&255); (y)[1] = (unsigned char)((x)&255); }
#define LOAD16(x,y) { x = ((ushort16)((y)[0] & 255)<<8) | ((ushort16)((y)[1] & 255)); }
static ushort16 _mul_inv(ushort16 x)
static ushort16 s_mul_inv(ushort16 x)
{
ushort16 y = x;
unsigned i;
@ -61,12 +61,12 @@ static ushort16 _mul_inv(ushort16 x)
return LOW16(y);
}
static ushort16 _add_inv(ushort16 x)
static ushort16 s_add_inv(ushort16 x)
{
return LOW16(0 - x);
}
static int _setup_key(const unsigned char *key, symmetric_key *skey)
static int s_setup_key(const unsigned char *key, symmetric_key *skey)
{
int i, j;
ushort16 *e_key = skey->idea.ek;
@ -83,22 +83,22 @@ static int _setup_key(const unsigned char *key, symmetric_key *skey)
/* prepare dec key */
for (i = 0; i < LTC_IDEA_ROUNDS; i++) {
d_key[i*6+0] = _mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+0]);
d_key[i*6+1] = _add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+1+(i>0 ? 1 : 0)]);
d_key[i*6+2] = _add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+2-(i>0 ? 1 : 0)]);
d_key[i*6+3] = _mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+3]);
d_key[i*6+4] = e_key[(LTC_IDEA_ROUNDS-1-i)*6+4];
d_key[i*6+5] = e_key[(LTC_IDEA_ROUNDS-1-i)*6+5];
d_key[i*6+0] = s_mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+0]);
d_key[i*6+1] = s_add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+1+(i>0 ? 1 : 0)]);
d_key[i*6+2] = s_add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+2-(i>0 ? 1 : 0)]);
d_key[i*6+3] = s_mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+3]);
d_key[i*6+4] = e_key[(LTC_IDEA_ROUNDS-1-i)*6+4];
d_key[i*6+5] = e_key[(LTC_IDEA_ROUNDS-1-i)*6+5];
}
d_key[i*6+0] = _mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+0]);
d_key[i*6+1] = _add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+1]);
d_key[i*6+2] = _add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+2]);
d_key[i*6+3] = _mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+3]);
d_key[i*6+0] = s_mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+0]);
d_key[i*6+1] = s_add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+1]);
d_key[i*6+2] = s_add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+2]);
d_key[i*6+3] = s_mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+3]);
return CRYPT_OK;
}
static int _process_block(const unsigned char *in, unsigned char *out, const ushort16 *m_key)
static int s_process_block(const unsigned char *in, unsigned char *out, const ushort16 *m_key)
{
int i;
ushort16 x0, x1, x2, x3, t0, t1;
@ -146,12 +146,12 @@ int idea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
if (num_rounds != 0 && num_rounds != 8) return CRYPT_INVALID_ROUNDS;
if (keylen != 16) return CRYPT_INVALID_KEYSIZE;
return _setup_key(key, skey);
return s_setup_key(key, skey);
}
int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _process_block(pt, ct, skey->idea.ek);
int err = s_process_block(pt, ct, skey->idea.ek);
#ifdef LTC_CLEAN_STACK
burn_stack(sizeof(ushort16) * 6 + sizeof(int));
#endif
@ -160,7 +160,7 @@ int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric
int idea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _process_block(ct, pt, skey->idea.dk);
int err = s_process_block(ct, pt, skey->idea.dk);
#ifdef LTC_CLEAN_STACK
burn_stack(sizeof(ushort16) * 6 + sizeof(int));
#endif

View File

@ -102,7 +102,7 @@ int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
static int s_noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#else
int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#endif
@ -142,7 +142,7 @@ int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
#ifdef LTC_CLEAN_STACK
int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _noekeon_ecb_encrypt(pt, ct, skey);
int err = s_noekeon_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(ulong32) * 5 + sizeof(int));
return err;
}
@ -156,7 +156,7 @@ int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
static int s_noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#else
int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#endif
@ -195,7 +195,7 @@ int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmet
#ifdef LTC_CLEAN_STACK
int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _noekeon_ecb_decrypt(ct, pt, skey);
int err = s_noekeon_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(ulong32) * 5 + sizeof(int));
return err;
}

View File

@ -139,7 +139,7 @@ int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _rc2_ecb_encrypt( const unsigned char *pt,
static int s_rc2_ecb_encrypt( const unsigned char *pt,
unsigned char *ct,
const symmetric_key *skey)
#else
@ -200,7 +200,7 @@ int rc2_ecb_encrypt( const unsigned char *pt,
unsigned char *ct,
const symmetric_key *skey)
{
int err = _rc2_ecb_encrypt(pt, ct, skey);
int err = s_rc2_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 5);
return err;
}
@ -217,7 +217,7 @@ int rc2_ecb_encrypt( const unsigned char *pt,
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _rc2_ecb_decrypt( const unsigned char *ct,
static int s_rc2_ecb_decrypt( const unsigned char *ct,
unsigned char *pt,
const symmetric_key *skey)
#else
@ -279,7 +279,7 @@ int rc2_ecb_decrypt( const unsigned char *ct,
unsigned char *pt,
const symmetric_key *skey)
{
int err = _rc2_ecb_decrypt(ct, pt, skey);
int err = s_rc2_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 4 + sizeof(int));
return err;
}

View File

@ -43,7 +43,7 @@ static const ulong32 stab[50] = {
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
static int s_rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#else
int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#endif
@ -104,7 +104,7 @@ int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
int x;
x = _rc5_setup(key, keylen, num_rounds, skey);
x = s_rc5_setup(key, keylen, num_rounds, skey);
burn_stack(sizeof(ulong32) * 122 + sizeof(int));
return x;
}
@ -118,7 +118,7 @@ int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
static int s_rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#else
int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#endif
@ -164,7 +164,7 @@ int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
#ifdef LTC_CLEAN_STACK
int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _rc5_ecb_encrypt(pt, ct, skey);
int err = s_rc5_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
return err;
}
@ -178,7 +178,7 @@ int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
static int s_rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#else
int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#endif
@ -225,7 +225,7 @@ int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_
#ifdef LTC_CLEAN_STACK
int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _rc5_ecb_decrypt(ct, pt, skey);
int err = s_rc5_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
return err;
}

View File

@ -40,7 +40,7 @@ static const ulong32 stab[44] = {
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
static int s_rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#else
int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#endif
@ -99,7 +99,7 @@ int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
int x;
x = _rc6_setup(key, keylen, num_rounds, skey);
x = s_rc6_setup(key, keylen, num_rounds, skey);
burn_stack(sizeof(ulong32) * 122);
return x;
}
@ -112,7 +112,7 @@ int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
@param skey The key as scheduled
*/
#ifdef LTC_CLEAN_STACK
static int _rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
static int s_rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#else
int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#endif
@ -154,7 +154,7 @@ int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
#ifdef LTC_CLEAN_STACK
int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _rc6_ecb_encrypt(pt, ct, skey);
int err = s_rc6_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(ulong32) * 6 + sizeof(int));
return err;
}
@ -167,7 +167,7 @@ int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
@param skey The key as scheduled
*/
#ifdef LTC_CLEAN_STACK
static int _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
static int s_rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#else
int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#endif
@ -211,7 +211,7 @@ int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_
#ifdef LTC_CLEAN_STACK
int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _rc6_ecb_decrypt(ct, pt, skey);
int err = s_rc6_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(ulong32) * 6 + sizeof(int));
return err;
}

View File

@ -91,7 +91,7 @@ const struct ltc_cipher_descriptor safer_k64_desc = {
/******************* Types ****************************************************/
#ifdef LTC_CLEAN_STACK
static void _safer_expand_userkey(const unsigned char *userkey_1,
static void s_safer_expand_userkey(const unsigned char *userkey_1,
const unsigned char *userkey_2,
unsigned int nof_rounds,
int strengthened,
@ -166,7 +166,7 @@ static void safer_expand_userkey(const unsigned char *userkey_1,
int strengthened,
safer_key_t key)
{
_safer_expand_userkey(userkey_1, userkey_2, nof_rounds, strengthened, key);
s_safer_expand_userkey(userkey_1, userkey_2, nof_rounds, strengthened, key);
burn_stack(sizeof(unsigned char) * (2 * (LTC_SAFER_BLOCK_LEN + 1)) + sizeof(unsigned int)*2);
}
#endif
@ -240,7 +240,7 @@ int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symm
}
#ifdef LTC_CLEAN_STACK
static int _safer_ecb_encrypt(const unsigned char *pt,
static int s_safer_ecb_encrypt(const unsigned char *pt,
unsigned char *ct,
const symmetric_key *skey)
#else
@ -287,14 +287,14 @@ int safer_ecb_encrypt(const unsigned char *pt,
unsigned char *ct,
const symmetric_key *skey)
{
int err = _safer_ecb_encrypt(pt, ct, skey);
int err = s_safer_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
return err;
}
#endif
#ifdef LTC_CLEAN_STACK
static int _safer_ecb_decrypt(const unsigned char *ct,
static int s_safer_ecb_decrypt(const unsigned char *ct,
unsigned char *pt,
const symmetric_key *skey)
#else
@ -342,7 +342,7 @@ int safer_ecb_decrypt(const unsigned char *ct,
unsigned char *pt,
const symmetric_key *skey)
{
int err = _safer_ecb_decrypt(ct, pt, skey);
int err = s_safer_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
return err;
}

View File

@ -137,37 +137,37 @@ const struct ltc_cipher_descriptor saferp_desc =
#ifdef LTC_SMALL_CODE
static void _round(unsigned char *b, int i, const symmetric_key *skey)
static void s_round(unsigned char *b, int i, const symmetric_key *skey)
{
ROUND(b, i);
}
static void _iround(unsigned char *b, int i, const symmetric_key *skey)
static void s_iround(unsigned char *b, int i, const symmetric_key *skey)
{
iROUND(b, i);
}
static void _lt(unsigned char *b, unsigned char *b2)
static void s_lt(unsigned char *b, unsigned char *b2)
{
LT(b, b2);
}
static void _ilt(unsigned char *b, unsigned char *b2)
static void s_ilt(unsigned char *b, unsigned char *b2)
{
iLT(b, b2);
}
#undef ROUND
#define ROUND(b, i) _round(b, i, skey)
#define ROUND(b, i) s_round(b, i, skey)
#undef iROUND
#define iROUND(b, i) _iround(b, i, skey)
#define iROUND(b, i) s_iround(b, i, skey)
#undef LT
#define LT(b, b2) _lt(b, b2)
#define LT(b, b2) s_lt(b, b2)
#undef iLT
#define iLT(b, b2) _ilt(b, b2)
#define iLT(b, b2) s_ilt(b, b2)
#endif

View File

@ -27,7 +27,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
};
/* linear transformation */
#define _lt(i,a,b,c,d,e) { \
#define s_lt(i,a,b,c,d,e) { \
a = ROLc(a, 13); \
c = ROLc(c, 3); \
d = ROLc(d ^ c ^ (a << 3), 7); \
@ -37,7 +37,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
}
/* inverse linear transformation */
#define _ilt(i,a,b,c,d,e) { \
#define s_ilt(i,a,b,c,d,e) { \
c = RORc(c, 22); \
a = RORc(a, 5); \
c ^= d ^ (b << 7); \
@ -50,32 +50,32 @@ const struct ltc_cipher_descriptor serpent_desc = {
}
/* order of output from S-box functions */
#define _beforeS0(f) f(0,a,b,c,d,e)
#define _afterS0(f) f(1,b,e,c,a,d)
#define _afterS1(f) f(2,c,b,a,e,d)
#define _afterS2(f) f(3,a,e,b,d,c)
#define _afterS3(f) f(4,e,b,d,c,a)
#define _afterS4(f) f(5,b,a,e,c,d)
#define _afterS5(f) f(6,a,c,b,e,d)
#define _afterS6(f) f(7,a,c,d,b,e)
#define _afterS7(f) f(8,d,e,b,a,c)
#define s_beforeS0(f) f(0,a,b,c,d,e)
#define s_afterS0(f) f(1,b,e,c,a,d)
#define s_afterS1(f) f(2,c,b,a,e,d)
#define s_afterS2(f) f(3,a,e,b,d,c)
#define s_afterS3(f) f(4,e,b,d,c,a)
#define s_afterS4(f) f(5,b,a,e,c,d)
#define s_afterS5(f) f(6,a,c,b,e,d)
#define s_afterS6(f) f(7,a,c,d,b,e)
#define s_afterS7(f) f(8,d,e,b,a,c)
/* order of output from inverse S-box functions */
#define _beforeI7(f) f(8,a,b,c,d,e)
#define _afterI7(f) f(7,d,a,b,e,c)
#define _afterI6(f) f(6,a,b,c,e,d)
#define _afterI5(f) f(5,b,d,e,c,a)
#define _afterI4(f) f(4,b,c,e,a,d)
#define _afterI3(f) f(3,a,b,e,c,d)
#define _afterI2(f) f(2,b,d,e,c,a)
#define _afterI1(f) f(1,a,b,c,e,d)
#define _afterI0(f) f(0,a,d,b,e,c)
#define s_beforeI7(f) f(8,a,b,c,d,e)
#define s_afterI7(f) f(7,d,a,b,e,c)
#define s_afterI6(f) f(6,a,b,c,e,d)
#define s_afterI5(f) f(5,b,d,e,c,a)
#define s_afterI4(f) f(4,b,c,e,a,d)
#define s_afterI3(f) f(3,a,b,e,c,d)
#define s_afterI2(f) f(2,b,d,e,c,a)
#define s_afterI1(f) f(1,a,b,c,e,d)
#define s_afterI0(f) f(0,a,d,b,e,c)
/* The instruction sequences for the S-box functions
* come from Dag Arne Osvik's paper "Speeding up Serpent".
*/
#define _s0(i, r0, r1, r2, r3, r4) { \
#define s_s0(i, r0, r1, r2, r3, r4) { \
r3 ^= r0; \
r4 = r1; \
r1 &= r3; \
@ -96,7 +96,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r4 ^= r3; \
}
#define _i0(i, r0, r1, r2, r3, r4) { \
#define s_i0(i, r0, r1, r2, r3, r4) { \
r2 = ~r2; \
r4 = r1; \
r1 |= r0; \
@ -118,7 +118,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r4 ^= r2; \
}
#define _s1(i, r0, r1, r2, r3, r4) { \
#define s_s1(i, r0, r1, r2, r3, r4) { \
r0 = ~r0; \
r2 = ~r2; \
r4 = r0; \
@ -139,7 +139,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r0 ^= r4; \
}
#define _i1(i, r0, r1, r2, r3, r4) { \
#define s_i1(i, r0, r1, r2, r3, r4) { \
r4 = r1; \
r1 ^= r3; \
r3 &= r1; \
@ -161,7 +161,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r3 ^= r1; \
}
#define _s2(i, r0, r1, r2, r3, r4) { \
#define s_s2(i, r0, r1, r2, r3, r4) { \
r4 = r0; \
r0 &= r2; \
r0 ^= r3; \
@ -180,7 +180,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r4 = ~r4; \
}
#define _i2(i, r0, r1, r2, r3, r4) { \
#define s_i2(i, r0, r1, r2, r3, r4) { \
r2 ^= r3; \
r3 ^= r0; \
r4 = r3; \
@ -202,7 +202,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r3 ^= r0; \
}
#define _s3(i, r0, r1, r2, r3, r4) { \
#define s_s3(i, r0, r1, r2, r3, r4) { \
r4 = r0; \
r0 |= r3; \
r3 ^= r1; \
@ -224,7 +224,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r1 ^= r0; \
}
#define _i3(i, r0, r1, r2, r3, r4) { \
#define s_i3(i, r0, r1, r2, r3, r4) { \
r4 = r2; \
r2 ^= r1; \
r1 &= r2; \
@ -245,7 +245,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r2 ^= r4; \
}
#define _s4(i, r0, r1, r2, r3, r4) { \
#define s_s4(i, r0, r1, r2, r3, r4) { \
r1 ^= r3; \
r3 = ~r3; \
r2 ^= r3; \
@ -268,7 +268,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r4 ^= r2; \
}
#define _i4(i, r0, r1, r2, r3, r4) { \
#define s_i4(i, r0, r1, r2, r3, r4) { \
r4 = r2; \
r2 &= r3; \
r2 ^= r1; \
@ -291,7 +291,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r2 ^= r1; \
}
#define _s5(i, r0, r1, r2, r3, r4) { \
#define s_s5(i, r0, r1, r2, r3, r4) { \
r0 ^= r1; \
r1 ^= r3; \
r3 = ~r3; \
@ -313,7 +313,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r2 ^= r4; \
}
#define _i5(i, r0, r1, r2, r3, r4) { \
#define s_i5(i, r0, r1, r2, r3, r4) { \
r1 = ~r1; \
r4 = r3; \
r2 ^= r1; \
@ -335,7 +335,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r4 = ~r4; \
}
#define _s6(i, r0, r1, r2, r3, r4) { \
#define s_s6(i, r0, r1, r2, r3, r4) { \
r2 = ~r2; \
r4 = r3; \
r3 &= r0; \
@ -356,7 +356,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r2 ^= r3; \
}
#define _i6(i, r0, r1, r2, r3, r4) { \
#define s_i6(i, r0, r1, r2, r3, r4) { \
r0 ^= r2; \
r4 = r2; \
r2 &= r0; \
@ -376,7 +376,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r4 ^= r0; \
}
#define _s7(i, r0, r1, r2, r3, r4) { \
#define s_s7(i, r0, r1, r2, r3, r4) { \
r4 = r2; \
r2 &= r1; \
r2 ^= r3; \
@ -399,7 +399,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
r4 ^= r1; \
}
#define _i7(i, r0, r1, r2, r3, r4) { \
#define s_i7(i, r0, r1, r2, r3, r4) { \
r4 = r2; \
r2 ^= r0; \
r0 &= r3; \
@ -422,28 +422,28 @@ const struct ltc_cipher_descriptor serpent_desc = {
}
/* key xor */
#define _kx(r, a, b, c, d, e) { \
#define s_kx(r, a, b, c, d, e) { \
a ^= k[4 * r + 0]; \
b ^= k[4 * r + 1]; \
c ^= k[4 * r + 2]; \
d ^= k[4 * r + 3]; \
}
#define _lk(r, a, b, c, d, e) { \
#define s_lk(r, a, b, c, d, e) { \
a = k[(8-r)*4 + 0]; \
b = k[(8-r)*4 + 1]; \
c = k[(8-r)*4 + 2]; \
d = k[(8-r)*4 + 3]; \
}
#define _sk(r, a, b, c, d, e) { \
#define s_sk(r, a, b, c, d, e) { \
k[(8-r)*4 + 4] = a; \
k[(8-r)*4 + 5] = b; \
k[(8-r)*4 + 6] = c; \
k[(8-r)*4 + 7] = d; \
}
static int _setup_key(const unsigned char *key, int keylen, int rounds, ulong32 *k)
static int s_setup_key(const unsigned char *key, int keylen, int rounds, ulong32 *k)
{
int i;
ulong32 t;
@ -467,22 +467,22 @@ static int _setup_key(const unsigned char *key, int keylen, int rounds, ulong32
k -= 20;
for (i = 0; i < rounds/8; i++) {
_afterS2(_lk); _afterS2(_s3); _afterS3(_sk);
_afterS1(_lk); _afterS1(_s2); _afterS2(_sk);
_afterS0(_lk); _afterS0(_s1); _afterS1(_sk);
_beforeS0(_lk); _beforeS0(_s0); _afterS0(_sk);
s_afterS2(s_lk); s_afterS2(s_s3); s_afterS3(s_sk);
s_afterS1(s_lk); s_afterS1(s_s2); s_afterS2(s_sk);
s_afterS0(s_lk); s_afterS0(s_s1); s_afterS1(s_sk);
s_beforeS0(s_lk); s_beforeS0(s_s0); s_afterS0(s_sk);
k += 8*4;
_afterS6(_lk); _afterS6(_s7); _afterS7(_sk);
_afterS5(_lk); _afterS5(_s6); _afterS6(_sk);
_afterS4(_lk); _afterS4(_s5); _afterS5(_sk);
_afterS3(_lk); _afterS3(_s4); _afterS4(_sk);
s_afterS6(s_lk); s_afterS6(s_s7); s_afterS7(s_sk);
s_afterS5(s_lk); s_afterS5(s_s6); s_afterS6(s_sk);
s_afterS4(s_lk); s_afterS4(s_s5); s_afterS5(s_sk);
s_afterS3(s_lk); s_afterS3(s_s4); s_afterS4(s_sk);
}
_afterS2(_lk); _afterS2(_s3); _afterS3(_sk);
s_afterS2(s_lk); s_afterS2(s_s3); s_afterS3(s_sk);
return CRYPT_OK;
}
static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
static int s_enc_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
{
ulong32 a, b, c, d, e;
unsigned int i = 1;
@ -493,14 +493,14 @@ static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32
LOAD32L(d, in + 12);
do {
_beforeS0(_kx); _beforeS0(_s0); _afterS0(_lt);
_afterS0(_kx); _afterS0(_s1); _afterS1(_lt);
_afterS1(_kx); _afterS1(_s2); _afterS2(_lt);
_afterS2(_kx); _afterS2(_s3); _afterS3(_lt);
_afterS3(_kx); _afterS3(_s4); _afterS4(_lt);
_afterS4(_kx); _afterS4(_s5); _afterS5(_lt);
_afterS5(_kx); _afterS5(_s6); _afterS6(_lt);
_afterS6(_kx); _afterS6(_s7);
s_beforeS0(s_kx); s_beforeS0(s_s0); s_afterS0(s_lt);
s_afterS0(s_kx); s_afterS0(s_s1); s_afterS1(s_lt);
s_afterS1(s_kx); s_afterS1(s_s2); s_afterS2(s_lt);
s_afterS2(s_kx); s_afterS2(s_s3); s_afterS3(s_lt);
s_afterS3(s_kx); s_afterS3(s_s4); s_afterS4(s_lt);
s_afterS4(s_kx); s_afterS4(s_s5); s_afterS5(s_lt);
s_afterS5(s_kx); s_afterS5(s_s6); s_afterS6(s_lt);
s_afterS6(s_kx); s_afterS6(s_s7);
if (i == 4) break;
@ -511,10 +511,10 @@ static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32
d = a;
a = e;
k += 32;
_beforeS0(_lt);
s_beforeS0(s_lt);
} while (1);
_afterS7(_kx);
s_afterS7(s_kx);
STORE32L(d, out + 0);
STORE32L(e, out + 4);
@ -524,7 +524,7 @@ static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32
return CRYPT_OK;
}
static int _dec_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
static int s_dec_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
{
ulong32 a, b, c, d, e;
unsigned int i;
@ -537,7 +537,7 @@ static int _dec_block(const unsigned char *in, unsigned char *out, const ulong32
i = 4;
k += 96;
_beforeI7(_kx);
s_beforeI7(s_kx);
goto start;
do {
@ -545,16 +545,16 @@ static int _dec_block(const unsigned char *in, unsigned char *out, const ulong32
b = d;
d = e;
k -= 32;
_beforeI7(_ilt);
s_beforeI7(s_ilt);
start:
_beforeI7(_i7); _afterI7(_kx);
_afterI7(_ilt); _afterI7(_i6); _afterI6(_kx);
_afterI6(_ilt); _afterI6(_i5); _afterI5(_kx);
_afterI5(_ilt); _afterI5(_i4); _afterI4(_kx);
_afterI4(_ilt); _afterI4(_i3); _afterI3(_kx);
_afterI3(_ilt); _afterI3(_i2); _afterI2(_kx);
_afterI2(_ilt); _afterI2(_i1); _afterI1(_kx);
_afterI1(_ilt); _afterI1(_i0); _afterI0(_kx);
s_beforeI7(s_i7); s_afterI7(s_kx);
s_afterI7(s_ilt); s_afterI7(s_i6); s_afterI6(s_kx);
s_afterI6(s_ilt); s_afterI6(s_i5); s_afterI5(s_kx);
s_afterI5(s_ilt); s_afterI5(s_i4); s_afterI4(s_kx);
s_afterI4(s_ilt); s_afterI4(s_i3); s_afterI3(s_kx);
s_afterI3(s_ilt); s_afterI3(s_i2); s_afterI2(s_kx);
s_afterI2(s_ilt); s_afterI2(s_i1); s_afterI1(s_kx);
s_afterI1(s_ilt); s_afterI1(s_i0); s_afterI0(s_kx);
} while (--i != 0);
STORE32L(a, out + 0);
@ -575,7 +575,7 @@ int serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
if (num_rounds != 0 && num_rounds != 32) return CRYPT_INVALID_ROUNDS;
if (keylen != 16 && keylen != 24 && keylen != 32) return CRYPT_INVALID_KEYSIZE;
err = _setup_key(key, keylen, 32, skey->serpent.k);
err = s_setup_key(key, keylen, 32, skey->serpent.k);
#ifdef LTC_CLEAN_STACK
burn_stack(sizeof(ulong32) * 14 + sizeof(int));
#endif
@ -584,7 +584,7 @@ int serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _enc_block(pt, ct, skey->serpent.k);
int err = s_enc_block(pt, ct, skey->serpent.k);
#ifdef LTC_CLEAN_STACK
burn_stack(sizeof(ulong32) * 5 + sizeof(int));
#endif
@ -593,7 +593,7 @@ int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
int serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _dec_block(ct, pt, skey->serpent.k);
int err = s_dec_block(ct, pt, skey->serpent.k);
#ifdef LTC_CLEAN_STACK
burn_stack(sizeof(ulong32) * 5 + sizeof(int));
#endif

View File

@ -133,7 +133,7 @@ static unsigned ig_func(unsigned w, int *kp, const unsigned char *key)
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
static int s_skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#else
int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#endif
@ -183,7 +183,7 @@ int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
#ifdef LTC_CLEAN_STACK
int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _skipjack_ecb_encrypt(pt, ct, skey);
int err = s_skipjack_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(unsigned) * 8 + sizeof(int) * 2);
return err;
}
@ -197,7 +197,7 @@ int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
static int s_skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#else
int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#endif
@ -251,7 +251,7 @@ int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symme
#ifdef LTC_CLEAN_STACK
int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err = _skipjack_ecb_decrypt(ct, pt, skey);
int err = s_skipjack_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(unsigned) * 7 + sizeof(int) * 2);
return err;
}

View File

@ -83,7 +83,7 @@ static const unsigned char qbox[2][4][16] = {
/* computes S_i[x] */
#ifdef LTC_CLEAN_STACK
static ulong32 _sbox(int i, ulong32 x)
static ulong32 s_sbox(int i, ulong32 x)
#else
static ulong32 sbox(int i, ulong32 x)
#endif
@ -125,7 +125,7 @@ static ulong32 sbox(int i, ulong32 x)
static ulong32 sbox(int i, ulong32 x)
{
ulong32 y;
y = _sbox(i, x);
y = s_sbox(i, x);
burn_stack(sizeof(unsigned char) * 11);
return y;
}
@ -282,7 +282,7 @@ static void h_func(const unsigned char *in, unsigned char *out, const unsigned c
#else
#ifdef LTC_CLEAN_STACK
static ulong32 _g_func(ulong32 x, const symmetric_key *key)
static ulong32 s_g_func(ulong32 x, const symmetric_key *key)
#else
static ulong32 g_func(ulong32 x, const symmetric_key *key)
#endif
@ -318,7 +318,7 @@ static ulong32 g_func(ulong32 x, const symmetric_key *key)
static ulong32 g_func(ulong32 x, const symmetric_key *key)
{
ulong32 y;
y = _g_func(x, key);
y = s_g_func(x, key);
burn_stack(sizeof(unsigned char) * 4 + sizeof(ulong32));
return y;
}
@ -335,7 +335,7 @@ static ulong32 g_func(ulong32 x, const symmetric_key *key)
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
static int s_twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#else
int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#endif
@ -448,7 +448,7 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
int x;
x = _twofish_setup(key, keylen, num_rounds, skey);
x = s_twofish_setup(key, keylen, num_rounds, skey);
burn_stack(sizeof(int) * 7 + sizeof(unsigned char) * 56 + sizeof(ulong32) * 2);
return x;
}
@ -462,7 +462,7 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
static int s_twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#else
int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
#endif
@ -522,7 +522,7 @@ int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
#ifdef LTC_CLEAN_STACK
int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
{
int err = _twofish_ecb_encrypt(pt, ct, skey);
int err = s_twofish_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(ulong32) * 10 + sizeof(int));
return err;
}
@ -536,7 +536,7 @@ int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
@return CRYPT_OK if successful
*/
#ifdef LTC_CLEAN_STACK
static int _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
static int s_twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#else
int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
#endif
@ -598,7 +598,7 @@ int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmet
#ifdef LTC_CLEAN_STACK
int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
{
int err =_twofish_ecb_decrypt(ct, pt, skey);
int err = s_twofish_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(ulong32) * 10 + sizeof(int));
return err;
}

View File

@ -55,20 +55,20 @@ int rsa_exptmod(const unsigned char *in, unsigned long inlen,
void rsa_free(rsa_key *key);
/* These use PKCS #1 v2.0 padding */
#define rsa_encrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, _key) \
rsa_encrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, LTC_PKCS_1_OAEP, _key)
#define rsa_encrypt_key(in, inlen, out, outlen, lparam, lparamlen, prng, prng_idx, hash_idx, key) \
rsa_encrypt_key_ex(in, inlen, out, outlen, lparam, lparamlen, prng, prng_idx, hash_idx, LTC_PKCS_1_OAEP, key)
#define rsa_decrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, _stat, _key) \
rsa_decrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, LTC_PKCS_1_OAEP, _stat, _key)
#define rsa_decrypt_key(in, inlen, out, outlen, lparam, lparamlen, hash_idx, stat, key) \
rsa_decrypt_key_ex(in, inlen, out, outlen, lparam, lparamlen, hash_idx, LTC_PKCS_1_OAEP, stat, key)
#define rsa_sign_hash(_in, _inlen, _out, _outlen, _prng, _prng_idx, _hash_idx, _saltlen, _key) \
rsa_sign_hash_ex(_in, _inlen, _out, _outlen, LTC_PKCS_1_PSS, _prng, _prng_idx, _hash_idx, _saltlen, _key)
#define rsa_sign_hash(in, inlen, out, outlen, prng, prng_idx, hash_idx, saltlen, key) \
rsa_sign_hash_ex(in, inlen, out, outlen, LTC_PKCS_1_PSS, prng, prng_idx, hash_idx, saltlen, key)
#define rsa_verify_hash(_sig, _siglen, _hash, _hashlen, _hash_idx, _saltlen, _stat, _key) \
rsa_verify_hash_ex(_sig, _siglen, _hash, _hashlen, LTC_PKCS_1_PSS, _hash_idx, _saltlen, _stat, _key)
#define rsa_verify_hash(sig, siglen, hash, hashlen, hash_idx, saltlen, stat, key) \
rsa_verify_hash_ex(sig, siglen, hash, hashlen, LTC_PKCS_1_PSS, hash_idx, saltlen, stat, key)
#define rsa_sign_saltlen_get_max(_hash_idx, _key) \
rsa_sign_saltlen_get_max_ex(LTC_PKCS_1_PSS, _hash_idx, _key)
#define rsa_sign_saltlen_get_max(hash_idx, key) \
rsa_sign_saltlen_get_max_ex(LTC_PKCS_1_PSS, hash_idx, key)
/* These can be switched between PKCS #1 v2.x and PKCS #1 v1.5 paddings */
int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen,

View File

@ -10,7 +10,7 @@
*/
#ifdef LTC_ADLER32
static const unsigned long _adler32_base = 65521;
static const unsigned long s_adler32_base = 65521;
void adler32_init(adler32_state *ctx)
{
@ -35,10 +35,10 @@ void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned lon
length--;
} while (length % 8 != 0);
if (s1 >= _adler32_base) {
s1 -= _adler32_base;
if (s1 >= s_adler32_base) {
s1 -= s_adler32_base;
}
s2 %= _adler32_base;
s2 %= s_adler32_base;
}
while (length > 0) {
@ -62,14 +62,14 @@ void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned lon
length -= 8;
input += 8;
if (s1 >= _adler32_base) {
s1 -= _adler32_base;
if (s1 >= s_adler32_base) {
s1 -= s_adler32_base;
}
s2 %= _adler32_base;
s2 %= s_adler32_base;
}
LTC_ARGCHKVD(s1 < _adler32_base);
LTC_ARGCHKVD(s2 < _adler32_base);
LTC_ARGCHKVD(s1 < s_adler32_base);
LTC_ARGCHKVD(s2 < s_adler32_base);
ctx->s[0] = (unsigned short)s1;
ctx->s[1] = (unsigned short)s2;

View File

@ -19,7 +19,7 @@ typedef struct {
#define C_STRINGIFY(s) { #s, s }
static const crypt_constant _crypt_constants[] = {
static const crypt_constant s_crypt_constants[] = {
C_STRINGIFY(CRYPT_OK),
C_STRINGIFY(CRYPT_ERROR),
@ -229,10 +229,10 @@ static const crypt_constant _crypt_constants[] = {
*/
int crypt_get_constant(const char* namein, int *valueout) {
int i;
int _crypt_constants_len = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]);
for (i=0; i<_crypt_constants_len; i++) {
if (XSTRCMP(_crypt_constants[i].name, namein) == 0) {
*valueout = _crypt_constants[i].value;
int count = sizeof(s_crypt_constants) / sizeof(s_crypt_constants[0]);
for (i=0; i<count; i++) {
if (XSTRCMP(s_crypt_constants[i].name, namein) == 0) {
*valueout = s_crypt_constants[i].value;
return 0;
}
}
@ -254,11 +254,11 @@ int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
unsigned int total_len = 0;
char *ptr;
int number_len;
int count = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]);
int count = sizeof(s_crypt_constants) / sizeof(s_crypt_constants[0]);
/* calculate amount of memory required for the list */
for (i=0; i<count; i++) {
number_len = snprintf(NULL, 0, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
number_len = snprintf(NULL, 0, "%s,%d\n", s_crypt_constants[i].name, s_crypt_constants[i].value);
if (number_len < 0) {
return -1;
}
@ -274,7 +274,7 @@ int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
/* build the names list */
ptr = names_list;
for (i=0; i<count; i++) {
number_len = snprintf(ptr, total_len, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
number_len = snprintf(ptr, total_len, "%s,%d\n", s_crypt_constants[i].name, s_crypt_constants[i].value);
if (number_len < 0) return -1;
if ((unsigned int)number_len > total_len) return -1;
total_len -= number_len;

View File

@ -20,7 +20,7 @@ typedef struct {
#define SZ_STRINGIFY_S(s) { #s, sizeof(struct s) }
#define SZ_STRINGIFY_T(s) { #s, sizeof(s) }
static const crypt_size _crypt_sizes[] = {
static const crypt_size s_crypt_sizes[] = {
/* hash state sizes */
SZ_STRINGIFY_S(ltc_hash_descriptor),
SZ_STRINGIFY_T(hash_state),
@ -290,10 +290,10 @@ static const crypt_size _crypt_sizes[] = {
*/
int crypt_get_size(const char* namein, unsigned int *sizeout) {
int i;
int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]);
int count = sizeof(s_crypt_sizes) / sizeof(s_crypt_sizes[0]);
for (i=0; i<count; i++) {
if (XSTRCMP(_crypt_sizes[i].name, namein) == 0) {
*sizeout = _crypt_sizes[i].size;
if (XSTRCMP(s_crypt_sizes[i].name, namein) == 0) {
*sizeout = s_crypt_sizes[i].size;
return 0;
}
}
@ -315,11 +315,11 @@ int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
unsigned int total_len = 0;
char *ptr;
int number_len;
int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]);
int count = sizeof(s_crypt_sizes) / sizeof(s_crypt_sizes[0]);
/* calculate amount of memory required for the list */
for (i=0; i<count; i++) {
number_len = snprintf(NULL, 0, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
number_len = snprintf(NULL, 0, "%s,%u\n", s_crypt_sizes[i].name, s_crypt_sizes[i].size);
if (number_len < 0) {
return -1;
}
@ -336,7 +336,7 @@ int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
/* build the names list */
ptr = names_list;
for (i=0; i<count; i++) {
number_len = snprintf(ptr, total_len, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
number_len = snprintf(ptr, total_len, "%s,%u\n", s_crypt_sizes[i].name, s_crypt_sizes[i].size);
if (number_len < 0) return -1;
if ((unsigned int)number_len > total_len) return -1;
total_len -= number_len;

View File

@ -40,7 +40,7 @@ LBL_ERROR:
return err;
}
static const pbes_properties _pbes1_types[] = {
static const pbes_properties s_pbes1_types[] = {
{ s_pkcs_5_alg1_wrap, "md2", "des", 8, 8 },
{ s_pkcs_5_alg1_wrap, "md2", "rc2", 8, 8 },
{ s_pkcs_5_alg1_wrap, "md5", "des", 8, 8 },
@ -55,23 +55,23 @@ typedef struct {
const char *oid;
} oid_to_pbes;
static const oid_to_pbes _pbes1_list[] = {
{ &_pbes1_types[0], "1.2.840.113549.1.5.1" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.1 pbeWithMD2AndDES-CBC */
{ &_pbes1_types[1], "1.2.840.113549.1.5.4" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.4 pbeWithMD2AndRC2-CBC */
{ &_pbes1_types[2], "1.2.840.113549.1.5.3" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.3 pbeWithMD5AndDES-CBC */
{ &_pbes1_types[3], "1.2.840.113549.1.5.6" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.6 pbeWithMD5AndRC2-CBC */
{ &_pbes1_types[4], "1.2.840.113549.1.5.10" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.10 pbeWithSHA1AndDES-CBC */
{ &_pbes1_types[5], "1.2.840.113549.1.5.11" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.11 pbeWithSHA1AndRC2-CBC */
{ &_pbes1_types[6], "1.2.840.113549.1.12.1.3" }, /* http://www.oid-info.com/get/1.2.840.113549.1.12.1.3 pbeWithSHAAnd3-KeyTripleDES-CBC */
static const oid_to_pbes s_pbes1_list[] = {
{ &s_pbes1_types[0], "1.2.840.113549.1.5.1" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.1 pbeWithMD2AndDES-CBC */
{ &s_pbes1_types[1], "1.2.840.113549.1.5.4" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.4 pbeWithMD2AndRC2-CBC */
{ &s_pbes1_types[2], "1.2.840.113549.1.5.3" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.3 pbeWithMD5AndDES-CBC */
{ &s_pbes1_types[3], "1.2.840.113549.1.5.6" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.6 pbeWithMD5AndRC2-CBC */
{ &s_pbes1_types[4], "1.2.840.113549.1.5.10" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.10 pbeWithSHA1AndDES-CBC */
{ &s_pbes1_types[5], "1.2.840.113549.1.5.11" }, /* http://www.oid-info.com/get/1.2.840.113549.1.5.11 pbeWithSHA1AndRC2-CBC */
{ &s_pbes1_types[6], "1.2.840.113549.1.12.1.3" }, /* http://www.oid-info.com/get/1.2.840.113549.1.12.1.3 pbeWithSHAAnd3-KeyTripleDES-CBC */
{ 0 },
};
static int s_pbes1_from_oid(const ltc_asn1_list *oid, pbes_properties *res)
{
unsigned int i;
for (i = 0; _pbes1_list[i].data != NULL; ++i) {
if (pk_oid_cmp_with_asn1(_pbes1_list[i].oid, oid) == CRYPT_OK) {
if (res != NULL) *res = *_pbes1_list[i].data;
for (i = 0; s_pbes1_list[i].data != NULL; ++i) {
if (pk_oid_cmp_with_asn1(s_pbes1_list[i].oid, oid) == CRYPT_OK) {
if (res != NULL) *res = *s_pbes1_list[i].data;
return CRYPT_OK;
}
}

View File

@ -4,15 +4,15 @@
#ifdef LTC_PBES
static const char * const _oid_pbes2 = "1.2.840.113549.1.5.13";
static const char * const _oid_pbkdf2 = "1.2.840.113549.1.5.12";
static const char * const s_oid_pbes2 = "1.2.840.113549.1.5.13";
static const char * const s_oid_pbkdf2 = "1.2.840.113549.1.5.12";
typedef struct {
const char *oid;
const char *id;
} oid_id_st;
static const oid_id_st _hmac_oid_names[] = {
static const oid_id_st s_hmac_oid_names[] = {
{ "1.2.840.113549.2.7", "sha1" },
{ "1.2.840.113549.2.8", "sha224" },
{ "1.2.840.113549.2.9", "sha256" },
@ -22,7 +22,7 @@ static const oid_id_st _hmac_oid_names[] = {
{ "1.2.840.113549.2.13", "sha512-256" },
};
static const pbes_properties _pbes2_default_types[] = {
static const pbes_properties s_pbes2_default_types[] = {
{ pkcs_5_alg2, "sha1", "des", 8, 0 },
{ pkcs_5_alg2, "sha1", "rc2", 4, 0 },
{ pkcs_5_alg2, "sha1", "3des", 24, 0 },
@ -36,29 +36,29 @@ typedef struct {
const char* oid;
} oid_to_pbes;
static const oid_to_pbes _pbes2_list[] = {
{ &_pbes2_default_types[0], "1.3.14.3.2.7" }, /* http://www.oid-info.com/get/1.3.14.3.2.7 desCBC */
{ &_pbes2_default_types[1], "1.2.840.113549.3.2" }, /* http://www.oid-info.com/get/1.2.840.113549.3.2 rc2CBC */
{ &_pbes2_default_types[2], "1.2.840.113549.3.7" }, /* http://www.oid-info.com/get/1.2.840.113549.3.7 des-EDE3-CBC */
{ &_pbes2_default_types[3], "2.16.840.1.101.3.4.1.2" }, /* http://www.oid-info.com/get/2.16.840.1.101.3.4.1.2 aes128-CBC */
{ &_pbes2_default_types[4], "2.16.840.1.101.3.4.1.22" }, /* http://www.oid-info.com/get/2.16.840.1.101.3.4.1.22 aes192-CBC */
{ &_pbes2_default_types[5], "2.16.840.1.101.3.4.1.42" }, /* http://www.oid-info.com/get/2.16.840.1.101.3.4.1.42 aes256-CBC */
static const oid_to_pbes s_pbes2_list[] = {
{ &s_pbes2_default_types[0], "1.3.14.3.2.7" }, /* http://www.oid-info.com/get/1.3.14.3.2.7 desCBC */
{ &s_pbes2_default_types[1], "1.2.840.113549.3.2" }, /* http://www.oid-info.com/get/1.2.840.113549.3.2 rc2CBC */
{ &s_pbes2_default_types[2], "1.2.840.113549.3.7" }, /* http://www.oid-info.com/get/1.2.840.113549.3.7 des-EDE3-CBC */
{ &s_pbes2_default_types[3], "2.16.840.1.101.3.4.1.2" }, /* http://www.oid-info.com/get/2.16.840.1.101.3.4.1.2 aes128-CBC */
{ &s_pbes2_default_types[4], "2.16.840.1.101.3.4.1.22" }, /* http://www.oid-info.com/get/2.16.840.1.101.3.4.1.22 aes192-CBC */
{ &s_pbes2_default_types[5], "2.16.840.1.101.3.4.1.42" }, /* http://www.oid-info.com/get/2.16.840.1.101.3.4.1.42 aes256-CBC */
};
static int s_pbes2_from_oid(const ltc_asn1_list *cipher_oid, const ltc_asn1_list *hmac_oid, pbes_properties *res)
{
unsigned int i;
for (i = 0; i < sizeof(_pbes2_list)/sizeof(_pbes2_list[0]); ++i) {
if (pk_oid_cmp_with_asn1(_pbes2_list[i].oid, cipher_oid) == CRYPT_OK) {
*res = *_pbes2_list[i].data;
for (i = 0; i < sizeof(s_pbes2_list)/sizeof(s_pbes2_list[0]); ++i) {
if (pk_oid_cmp_with_asn1(s_pbes2_list[i].oid, cipher_oid) == CRYPT_OK) {
*res = *s_pbes2_list[i].data;
break;
}
}
if (res->c == NULL) return CRYPT_INVALID_CIPHER;
if (hmac_oid != NULL) {
for (i = 0; i < sizeof(_hmac_oid_names)/sizeof(_hmac_oid_names[0]); ++i) {
if (pk_oid_cmp_with_asn1(_hmac_oid_names[i].oid, hmac_oid) == CRYPT_OK) {
res->h = _hmac_oid_names[i].id;
for (i = 0; i < sizeof(s_hmac_oid_names)/sizeof(s_hmac_oid_names[0]); ++i) {
if (pk_oid_cmp_with_asn1(s_hmac_oid_names[i].oid, hmac_oid) == CRYPT_OK) {
res->h = s_hmac_oid_names[i].id;
return CRYPT_OK;
}
}
@ -84,7 +84,7 @@ int pbes2_extract(const ltc_asn1_list *s, pbes_arg *res)
LTC_ARGCHK(s != NULL);
LTC_ARGCHK(res != NULL);
if ((err = pk_oid_cmp_with_asn1(_oid_pbes2, s)) != CRYPT_OK) return err;
if ((err = pk_oid_cmp_with_asn1(s_oid_pbes2, s)) != CRYPT_OK) return err;
if (!LTC_ASN1_IS_TYPE(s->next, LTC_ASN1_SEQUENCE) ||
!LTC_ASN1_IS_TYPE(s->next->child, LTC_ASN1_SEQUENCE) ||
@ -115,7 +115,7 @@ int pbes2_extract(const ltc_asn1_list *s, pbes_arg *res)
lkdf = s->next->child->child;
lenc = s->next->child->next->child;
if ((err = pk_oid_cmp_with_asn1(_oid_pbkdf2, lkdf)) != CRYPT_OK) return err;
if ((err = pk_oid_cmp_with_asn1(s_oid_pbkdf2, lkdf)) != CRYPT_OK) return err;
if (!LTC_ASN1_IS_TYPE(lkdf->next, LTC_ASN1_SEQUENCE) ||
!LTC_ASN1_IS_TYPE(lkdf->next->child, LTC_ASN1_OCTET_STRING) ||

View File

@ -14,11 +14,11 @@ typedef long64 i64;
typedef i64 gf[16];
static const u8
_9[32] = {9};
nine[32] = {9};
static const gf
gf0,
gf1 = {1},
_121665 = {0xDB41,1},
gf121665 = {0xDB41,1},
D = {0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203},
D2 = {0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406},
X = {0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169},
@ -195,7 +195,7 @@ int tweetnacl_crypto_scalarmult(u8 *q,const u8 *n,const u8 *p)
Z(a,a,c);
S(b,a);
Z(c,d,f);
M(a,c,_121665);
M(a,c,gf121665);
A(a,a,d);
M(c,c,a);
M(a,d,f);
@ -218,7 +218,7 @@ int tweetnacl_crypto_scalarmult(u8 *q,const u8 *n,const u8 *p)
int tweetnacl_crypto_scalarmult_base(u8 *q,const u8 *n)
{
return tweetnacl_crypto_scalarmult(q,n,_9);
return tweetnacl_crypto_scalarmult(q,n,nine);
}
static int tweetnacl_crypto_hash(u8 *out,const u8 *m,u64 n)

View File

@ -8,7 +8,7 @@
static const struct {
const char *OID;
const char *names[6];
} _curve_names[] = {
} s_curve_names[] = {
#ifdef LTC_ECC_SECP112R1
{
"1.3.132.0.6", { "SECP112R1", "ECC-112", NULL }
@ -216,13 +216,13 @@ int ecc_find_curve(const char *name_or_oid, const ltc_ecc_curve **cu)
*cu = NULL;
for (i = 0; _curve_names[i].OID != NULL && !OID; i++) {
if (XSTRCMP(_curve_names[i].OID, name_or_oid) == 0) {
OID = _curve_names[i].OID;
for (i = 0; s_curve_names[i].OID != NULL && !OID; i++) {
if (XSTRCMP(s_curve_names[i].OID, name_or_oid) == 0) {
OID = s_curve_names[i].OID;
}
for (j = 0; _curve_names[i].names[j] != NULL && !OID; j++) {
if (s_name_match(_curve_names[i].names[j], name_or_oid)) {
OID = _curve_names[i].OID;
for (j = 0; s_curve_names[i].names[j] != NULL && !OID; j++) {
if (s_name_match(s_curve_names[i].names[j], name_or_oid)) {
OID = s_curve_names[i].OID;
}
}
}

View File

@ -35,7 +35,7 @@ static int s_der_flexi_sequence_cmp(const ltc_asn1_list *flexi, der_flexi_check
return CRYPT_OK;
}
/* NOTE: _der_decode_pkcs8_flexi & related stuff can be shared with rsa_import_pkcs8() */
/* NOTE: s_der_decode_pkcs8_flexi & related stuff can be shared with rsa_import_pkcs8() */
int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen,
const void *pwd, unsigned long pwdlen,

View File

@ -15,7 +15,7 @@ int der_test(void)
#define LTC_DER_TESTS_PRINT_FLEXI
#endif
static const char _der_tests_stinky_root_cert[] =
static const char s_der_tests_stinky_root_cert[] =
"MIIFETCCA/mgAwIBAgIQbv53JNmv518t5lkCHE272jANBgkqhkiG9w0BAQUFADCB"
"lTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0IExha2Ug"
"Q2l0eTEeMBwGA1UEChMVVGhlIFVTRVJUUlVTVCBOZXR3b3JrMSEwHwYDVQQLExho"
@ -44,7 +44,7 @@ static const char _der_tests_stinky_root_cert[] =
"JeXwdFaRjbamiz3Irl+u7x/mhxdza6RvgBYylXRFMudANpeGsV7gDXlnfzpFDKHQ"
"niVwB7P5sbPFIlmIc+4/xRItkLIRjCVXaepgN9KYu3VOgiSDI6wXiTwP44/LUXQM"
"hetwa7s=";
const char _der_tests_cacert_root_cert[] =
const char ltc_der_tests_cacert_root_cert[] =
"MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290"
"IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB"
"IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA"
@ -84,7 +84,7 @@ const char _der_tests_cacert_root_cert[] =
"GCSNe9FINSkYQKyTYOGWhlC0elnYjyELn8+CkcY7v2vcB5G5l1YjqrZslMZIBjzk"
"zk6q5PYvCdxTby78dOs6Y5nCpqyJvKeyRKANihDjbPIky/qbn3BHLt4Ui9SyIAmW"
"omTxJBzcoTWcFbLUvFUufQb1nA5V9FrWk9p2rSVzTMVD";
const unsigned long _der_tests_cacert_root_cert_size = sizeof(_der_tests_cacert_root_cert);
const unsigned long ltc_der_tests_cacert_root_cert_size = sizeof(ltc_der_tests_cacert_root_cert);
/*
SEQUENCE(3 elem)
@ -203,35 +203,33 @@ SEQUENCE(3 elem)
BIT STRING(4096 bit)
*/
#define __ASN1_FMTSTRING_FMT "line: %d, type=%d, size=%lu, data=%p, self=%p, next=%p, prev=%p, parent=%p, child=%p"
#define __ASN1_FMTSTRING_VAL(l) __LINE__, (l)->type, (l)->size, (l)->data, (l), (l)->next, (l)->prev, (l)->parent, (l)->child
#define ASN1_FMTSTRING_FMT "line: %d, type=%d, size=%lu, data=%p, self=%p, next=%p, prev=%p, parent=%p, child=%p"
#define ASN1_FMTSTRING_VAL(l) __LINE__, (l)->type, (l)->size, (l)->data, (l), (l)->next, (l)->prev, (l)->parent, (l)->child
#define __ASN1_ERR(l) fprintf(stderr, __ASN1_FMTSTRING_FMT "\n", __ASN1_FMTSTRING_VAL(l)); \
#define ASN1_ERR(l) fprintf(stderr, ASN1_FMTSTRING_FMT "\n", ASN1_FMTSTRING_VAL(l)); \
exit(EXIT_FAILURE)
#define __CHECK_ASN1_HAS(l, w) do { if ((l)->w == NULL) { \
__ASN1_ERR(l);\
#define CHECK_ASN1_HAS(l, w) do { if ((l)->w == NULL) { \
ASN1_ERR(l);\
} } while(0)
#define __CHECK_ASN1_HAS_NO(l, w) do { if ((l)->w != NULL) { \
__ASN1_ERR(l);\
#define CHECK_ASN1_HAS_NO(l, w) do { if ((l)->w != NULL) { \
ASN1_ERR(l);\
} } while(0)
#define CHECK_ASN1_TYPE(l, t) do { if ((l)->type != (t)) { \
__ASN1_ERR(l);\
ASN1_ERR(l);\
} } while(0)
#define CHECK_ASN1_HAS_CHILD(l) __CHECK_ASN1_HAS(l, child)
#define CHECK_ASN1_HAS_NO_CHILD(l) __CHECK_ASN1_HAS_NO(l, child)
#define CHECK_ASN1_HAS_NEXT(l) __CHECK_ASN1_HAS(l, next)
#define CHECK_ASN1_HAS_NO_NEXT(l) __CHECK_ASN1_HAS_NO(l, next)
#define CHECK_ASN1_HAS_DATA(l) __CHECK_ASN1_HAS(l, data)
#define CHECK_ASN1_HAS_NO_DATA(l) __CHECK_ASN1_HAS_NO(l, data)
#define CHECK_ASN1_HAS_CHILD(l) CHECK_ASN1_HAS(l, child)
#define CHECK_ASN1_HAS_NO_CHILD(l) CHECK_ASN1_HAS_NO(l, child)
#define CHECK_ASN1_HAS_NEXT(l) CHECK_ASN1_HAS(l, next)
#define CHECK_ASN1_HAS_NO_NEXT(l) CHECK_ASN1_HAS_NO(l, next)
#define CHECK_ASN1_HAS_DATA(l) CHECK_ASN1_HAS(l, data)
#define CHECK_ASN1_HAS_NO_DATA(l) CHECK_ASN1_HAS_NO(l, data)
#ifdef LTC_DER_TESTS_PRINT_FLEXI
static void _der_tests_print_flexi(ltc_asn1_list* l, unsigned int level)
static void s_der_tests_print_flexi(ltc_asn1_list* l, unsigned int level)
{
char buf[1024];
const char* name = NULL;
@ -243,7 +241,7 @@ static void _der_tests_print_flexi(ltc_asn1_list* l, unsigned int level)
{
case LTC_ASN1_EOL:
name = "EOL";
snprintf(buf, sizeof(buf),__ASN1_FMTSTRING_FMT "\n", __ASN1_FMTSTRING_VAL(l));
snprintf(buf, sizeof(buf),__ASN1_FMTSTRING_FMT "\n", ASN1_FMTSTRING_VAL(l));
text = buf;
break;
case LTC_ASN1_BOOLEAN:
@ -397,32 +395,32 @@ static void _der_tests_print_flexi(ltc_asn1_list* l, unsigned int level)
fprintf(stderr, "WTF type=%i\n", l->type);
if (ostring) {
_der_tests_print_flexi(ostring, level + 1);
s_der_tests_print_flexi(ostring, level + 1);
der_free_sequence_flexi(ostring);
}
if (l->child)
_der_tests_print_flexi(l->child, level + 1);
s_der_tests_print_flexi(l->child, level + 1);
if (l->next)
_der_tests_print_flexi(l->next, level);
s_der_tests_print_flexi(l->next, level);
}
#endif
static void der_cacert_test(void)
{
unsigned char buf[sizeof(_der_tests_cacert_root_cert)];
unsigned char buf[sizeof(ltc_der_tests_cacert_root_cert)];
unsigned long len1 = sizeof(buf), len2;
ltc_asn1_list *decoded_list, *l, *l1, *l2;
DO(base64_decode(_der_tests_stinky_root_cert, sizeof(_der_tests_stinky_root_cert), buf, &len1));
DO(base64_decode(s_der_tests_stinky_root_cert, sizeof(s_der_tests_stinky_root_cert), buf, &len1));
len2 = len1;
DO(der_decode_sequence_flexi(buf, &len2, &decoded_list));
der_free_sequence_flexi(decoded_list);
len1 = sizeof(buf);
DO(base64_decode(_der_tests_cacert_root_cert, sizeof(_der_tests_cacert_root_cert), buf, &len1));
DO(base64_decode(ltc_der_tests_cacert_root_cert, sizeof(ltc_der_tests_cacert_root_cert), buf, &len1));
len2 = len1;
DO(der_decode_sequence_flexi(buf, &len2, &decoded_list));
CHECK_ASN1_TYPE(decoded_list, LTC_ASN1_SEQUENCE);
@ -435,7 +433,7 @@ static void der_cacert_test(void)
#ifdef LTC_DER_TESTS_PRINT_FLEXI
printf("\n\n--- test print start ---\n\n");
_der_tests_print_flexi(decoded_list, 0);
s_der_tests_print_flexi(decoded_list, 0);
printf("\n\n--- test print end ---\n\n");
#endif
@ -667,7 +665,7 @@ static void der_set_test(void)
*/
static void _der_oid_test(void)
static void s_der_oid_test(void)
{
static const unsigned char oid_x690_8_19_5_example[] = { 0x06, 0x03, 0x88, 0x37, 0x03 };
unsigned long len, oid[3];
@ -1127,13 +1125,13 @@ static int der_choice_n_custom_test(void)
return 0;
}
static void _der_decode_print(const void* p, unsigned long* plen)
static void s_der_decode_print(const void* p, unsigned long* plen)
{
ltc_asn1_list *list;
DO(der_decode_sequence_flexi(p, plen, &list));
#ifdef LTC_DER_TESTS_PRINT_FLEXI
fprintf(stderr, "\n\n");
_der_tests_print_flexi(list, 0);
s_der_tests_print_flexi(list, 0);
fprintf(stderr, "\n\n");
#endif
der_sequence_free(list);
@ -1183,7 +1181,7 @@ static void der_custom_test(void)
DO(der_length_custom_type(custom, &len, NULL));
len = sizeof(buf);
DO(der_encode_custom_type(custom, buf, &len));
_der_decode_print(buf, &len);
s_der_decode_print(buf, &len);
boolean = 0x0;
DO(der_decode_custom_type(buf, len, custom));
@ -1191,7 +1189,7 @@ static void der_custom_test(void)
DO(der_length_sequence(custom, 1, &len));
len = sizeof(buf);
DO(der_encode_sequence(custom, 1, buf, &len));
_der_decode_print(buf, &len);
s_der_decode_print(buf, &len);
boolean = 0x0;
DO(der_decode_sequence(buf, len, custom, 1));
@ -1200,29 +1198,29 @@ static void der_custom_test(void)
DO(der_length_custom_type(bool_ean, &len, NULL));
len = sizeof(buf);
DO(der_encode_custom_type(bool_ean, buf, &len));
_der_decode_print(buf, &len);
s_der_decode_print(buf, &len);
LTC_SET_ASN1_CUSTOM_PRIMITIVE(bool_ean, 0, LTC_ASN1_CL_CONTEXT_SPECIFIC, 0x8000, LTC_ASN1_BOOLEAN, &boolean, 1);
DO(der_decode_custom_type(buf, len, bool_ean));
len = sizeof(buf1);
_der_decode_print(buf1, &len);
s_der_decode_print(buf1, &len);
len = sizeof(buf2);
_der_decode_print(buf2, &len);
s_der_decode_print(buf2, &len);
len = sizeof(eckey_privc_der);
_der_decode_print(eckey_privc_der, &len);
s_der_decode_print(eckey_privc_der, &len);
len = sizeof(eckey_privs_der);
_der_decode_print(eckey_privs_der, &len);
s_der_decode_print(eckey_privs_der, &len);
}
typedef int (*_der_Xcode)(const void*, unsigned long, void*, unsigned long*);
typedef int (*s_der_Xcode)(const void*, unsigned long, void*, unsigned long*);
typedef struct {
_der_Xcode encode;
_der_Xcode decode;
s_der_Xcode encode;
s_der_Xcode decode;
const void* in;
size_t in_sz;
size_t factor;
@ -1260,8 +1258,8 @@ static void der_Xcode_run(const der_Xcode_t* x)
#endif
#define DER_XCODE_X(n, b, x) { \
(_der_Xcode)der_encode_ ## n, \
(_der_Xcode)der_decode_ ## n, \
(s_der_Xcode)der_encode_ ## n, \
(s_der_Xcode)der_decode_ ## n, \
b, \
sizeof(b), \
x, \
@ -1307,7 +1305,7 @@ static void der_Xcode_test(void)
DO(der_decode_sequence_flexi(teletex_neg_int, &i, &list));
#ifdef LTC_DER_TESTS_PRINT_FLEXI
fprintf(stderr, "\n\n");
_der_tests_print_flexi(list, 0);
s_der_tests_print_flexi(list, 0);
fprintf(stderr, "\n\n");
#endif
if (list->child == NULL || list->child->next == NULL)
@ -1327,13 +1325,13 @@ static void der_Xcode_test(void)
}
#ifdef LTC_TEST_READDIR
static int _der_decode_sequence_flexi(const void *in, unsigned long inlen, void* ctx)
static int s_der_decode_sequence_flexi(const void *in, unsigned long inlen, void* ctx)
{
ltc_asn1_list** list = ctx;
if (der_decode_sequence_flexi(in, &inlen, list) == CRYPT_OK) {
#ifdef LTC_DER_TESTS_PRINT_FLEXI
fprintf(stderr, "\n\n");
_der_tests_print_flexi(*list, 0);
s_der_tests_print_flexi(*list, 0);
fprintf(stderr, "\n\n");
#endif
der_sequence_free(*list);
@ -1343,16 +1341,16 @@ static int _der_decode_sequence_flexi(const void *in, unsigned long inlen, void*
#endif
static void _der_regression_test(void)
static void s_der_regression_test(void)
{
static const unsigned char _broken_sequence[] = {
static const unsigned char s_broken_sequence[] = {
0x30,0x41,0x02,0x84,0x7f,0xff,0xff,0xff,0x1e,0x41,0xb4,0x79,0xad,0x57,0x69,
0x05,0xb9,0x60,0xfe,0x14,0xea,0xdb,0x91,0xb0,0xcc,0xf3,0x48,0x43,0xda,0xb9,
0x16,0x17,0x3b,0xb8,0xc9,0xcd,0x02,0x1d,0x00,0xad,0xe6,0x59,0x88,0xd2,0x37,
0xd3,0x0f,0x9e,0xf4,0x1d,0xd4,0x24,0xa4,0xe1,0xc8,0xf1,0x69,0x67,0xcf,0x33,
0x65,0x81,0x3f,0xe8,0x78,0x62,0x36
};
static const unsigned char _addtl_bytes[] = {
static const unsigned char s_addtl_bytes[] = {
0x30,0x45,0x02,0x21,0x00,0xb7,0xba,0xba,0xe9,0x33,0x2b,0x54,0xb8,0xa3,0xa0,0x5b,0x70,0x04,0x57,
0x98,0x21,0xa8,0x87,0xa1,0xb2,0x14,0x65,0xf7,0xdb,0x8a,0x3d,0x49,0x1b,0x39,0xfd,0x2c,0x3f,0x02,
0x20,0x74,0x72,0x91,0xdd,0x2f,0x3f,0x44,0xaf,0x7a,0xce,0x68,0xea,0x33,0x43,0x1d,0x6f,0x94,0xe4,
@ -1370,17 +1368,17 @@ static void _der_regression_test(void)
mp_init_multi(&x, &y, NULL);
LTC_SET_ASN1(seq, 0, LTC_ASN1_INTEGER, x, 1UL);
LTC_SET_ASN1(seq, 1, LTC_ASN1_INTEGER, y, 1UL);
SHOULD_FAIL(der_decode_sequence(_broken_sequence, sizeof(_broken_sequence), seq, 2));
SHOULD_FAIL(der_decode_sequence(s_broken_sequence, sizeof(s_broken_sequence), seq, 2));
mp_cleanup_multi(&y, &x, NULL);
len = sizeof(_broken_sequence);
len = sizeof(s_broken_sequence);
mp_init_multi(&x, &y, NULL);
LTC_SET_ASN1(seq, 0, LTC_ASN1_INTEGER, x, 1UL);
LTC_SET_ASN1(seq, 1, LTC_ASN1_INTEGER, y, 1UL);
SHOULD_FAIL_WITH(der_decode_sequence(_addtl_bytes, sizeof(_addtl_bytes), seq, 2), CRYPT_INPUT_TOO_LONG);
SHOULD_FAIL_WITH(der_decode_sequence(s_addtl_bytes, sizeof(s_addtl_bytes), seq, 2), CRYPT_INPUT_TOO_LONG);
mp_cleanup_multi(&y, &x, NULL);
len = sizeof(_addtl_bytes);
_der_decode_print(_addtl_bytes, &len);
len = sizeof(s_addtl_bytes);
s_der_decode_print(s_addtl_bytes, &len);
len = sizeof(issue_507);
SHOULD_FAIL(der_decode_sequence_flexi(issue_507, &len, &l));
@ -1552,7 +1550,7 @@ static void der_toolong_test(void)
if (failed) exit(EXIT_FAILURE);
}
static void _der_recursion_limit(void)
static void s_der_recursion_limit(void)
{
unsigned int n, m;
unsigned long integer = 123, s;
@ -1614,23 +1612,23 @@ int der_test(void)
if (ltc_mp.name == NULL) return CRYPT_NOP;
_der_recursion_limit();
s_der_recursion_limit();
der_Xcode_test();
#ifdef LTC_TEST_READDIR
DO(test_process_dir("tests/asn1", &list, _der_decode_sequence_flexi, NULL, "DER ASN.1 special cases"));
DO(test_process_dir("tests/asn1", &list, s_der_decode_sequence_flexi, NULL, "DER ASN.1 special cases"));
#endif
der_custom_test();
_der_regression_test();
s_der_regression_test();
der_toolong_test();
der_cacert_test();
_der_oid_test();
s_der_oid_test();
y = 0xffffff00;
#if ULONG_MAX == ULLONG_MAX

View File

@ -4,7 +4,7 @@
#if defined(LTC_MDH)
static int _prime_test(void)
static int s_prime_test(void)
{
void *p, *g, *tmp;
int x, err, primality;
@ -49,7 +49,7 @@ done:
return err;
}
static int _dhparam_test(void)
static int s_dhparam_test(void)
{
dh_key k;
unsigned char buf[1024];
@ -135,7 +135,7 @@ static int _dhparam_test(void)
return CRYPT_OK;
}
static int _set_test(void)
static int s_set_test(void)
{
dh_key k1, k2, k3;
unsigned char buf[4096];
@ -308,7 +308,7 @@ static int _set_test(void)
return CRYPT_OK;
}
static int _basic_test(void)
static int s_basic_test(void)
{
unsigned char buf[3][4096];
unsigned long x, y, z;
@ -389,10 +389,10 @@ int dh_test(void)
if (ltc_mp.name == NULL) return CRYPT_NOP;
if (_prime_test() != CRYPT_OK) fails++;
if (_basic_test() != CRYPT_OK) fails++;
if (_dhparam_test() != CRYPT_OK) fails++;
if (_set_test() != CRYPT_OK) fails++;
if (s_prime_test() != CRYPT_OK) fails++;
if (s_basic_test() != CRYPT_OK) fails++;
if (s_dhparam_test() != CRYPT_OK) fails++;
if (s_set_test() != CRYPT_OK) fails++;
return fails > 0 ? CRYPT_FAIL_TESTVECTOR : CRYPT_OK;
}

View File

@ -123,7 +123,7 @@ static unsigned char dsaparam_der[] = {
};
static int _dsa_compat_test(void)
static int s_dsa_compat_test(void)
{
dsa_key key;
unsigned char tmp[1024], buf[1024];
@ -226,7 +226,7 @@ static int _dsa_compat_test(void)
return CRYPT_OK;
}
static int _dsa_wycheproof_test(void)
static int s_dsa_wycheproof_test(void)
{
/* test case from https://github.com/google/wycheproof/blob/master/testvectors/dsa_test.json
*
@ -307,8 +307,8 @@ int dsa_test(void)
if (ltc_mp.name == NULL) return CRYPT_NOP;
DO(_dsa_compat_test());
DO(_dsa_wycheproof_test());
DO(s_dsa_compat_test());
DO(s_dsa_wycheproof_test());
/* make a random key */
DO(dsa_generate_pqg(&yarrow_prng, find_prng("yarrow"), 20, 128, &key));

View File

@ -119,7 +119,7 @@ static const char* curvenames[] = {
#ifdef LTC_ECC_SHAMIR
static int _ecc_test_shamir(void)
static int s_ecc_test_shamir(void)
{
void *a, *modulus, *mp, *kA, *kB, *rA, *rB;
void *mu, *ma;
@ -199,7 +199,7 @@ static int _ecc_test_shamir(void)
#endif
/* https://github.com/libtom/libtomcrypt/issues/108 */
static int _ecc_issue108(void)
static int s_ecc_issue108(void)
{
void *a, *modulus, *order;
ecc_point *Q, *Result;
@ -235,7 +235,7 @@ done:
/* https://github.com/libtom/libtomcrypt/issues/443 */
/* https://github.com/libtom/libtomcrypt/issues/447 */
static int _ecc_issue443_447(void)
static int s_ecc_issue443_447(void)
{
const ltc_ecc_curve* cu;
ecc_key key;
@ -285,7 +285,7 @@ static int _ecc_issue443_447(void)
return CRYPT_OK;
}
static int _ecc_test_mp(void)
static int s_ecc_test_mp(void)
{
void *a, *modulus, *order;
ecc_point *G, *GG;
@ -348,7 +348,7 @@ done:
return err;
}
static int _ecc_old_api(void)
static int s_ecc_old_api(void)
{
unsigned char buf[4][4096], ch;
unsigned long x, y, z, s;
@ -489,7 +489,7 @@ static int _ecc_old_api(void)
return CRYPT_OK;
}
static int _ecc_key_cmp(const int should_type, const ecc_key *should, const ecc_key *is)
static int s_ecc_key_cmp(const int should_type, const ecc_key *should, const ecc_key *is)
{
if (should_type != is->type) return CRYPT_ERROR;
if (should_type == PK_PRIVATE) {
@ -508,7 +508,7 @@ static int _ecc_key_cmp(const int should_type, const ecc_key *should, const ecc_
return CRYPT_OK;
}
static int _ecc_new_api(void)
static int s_ecc_new_api(void)
{
int i, j, stat;
const ltc_ecc_curve* dp;
@ -596,7 +596,7 @@ static int _ecc_new_api(void)
for (j = 0; j < 2*(1+(int)privkey.dp.cofactor); j++) {
stat = ecc_recover_key(buf, len, data16, 16, j, LTC_ECCSIG_ANSIX962, &reckey);
if (stat != CRYPT_OK) continue; /* last two will almost always fail, only possible if x<(prime mod order) */
stat = _ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey);
stat = s_ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey);
if (stat == CRYPT_OK) found++;
}
if (found != 1) return CRYPT_FAIL_TESTVECTOR; /* unique match */
@ -620,7 +620,7 @@ static int _ecc_new_api(void)
return CRYPT_OK;
}
static int _ecc_import_export(void) {
static int s_ecc_import_export(void) {
const ltc_ecc_curve *cu;
ecc_key key, pri, pub;
unsigned char out[300];
@ -1310,138 +1310,138 @@ static int _ecc_import_export(void) {
/* import - raw keys */
DO(ecc_set_curve(cu, &key));
DO(ecc_set_key(raw_pri, sizeof(raw_pri), PK_PRIVATE, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
DO(ecc_set_curve(cu, &key));
DO(ecc_set_key(raw_pub, sizeof(raw_pub), PK_PUBLIC, &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
DO(ecc_set_curve(cu, &key));
DO(ecc_set_key(raw_pubc, sizeof(raw_pubc), PK_PUBLIC, &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
/* import - openssl compatible DER format */
DO(ecc_import_openssl(long_pri, sizeof(long_pri), &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
DO(ecc_import_openssl(long_pric, sizeof(long_pric), &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
DO(ecc_import_openssl(long_pub, sizeof(long_pub), &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
DO(ecc_import_openssl(long_pubc, sizeof(long_pubc), &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
DO(ecc_import_openssl(short_pri, sizeof(short_pri), &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
DO(ecc_import_openssl(short_pric, sizeof(short_pric), &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
DO(ecc_import_openssl(short_pub, sizeof(short_pub), &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
DO(ecc_import_openssl(short_pubc, sizeof(short_pubc), &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
/* import - private PKCS8 format - no password */
DO(ecc_import_pkcs8(long_pri_pkcs8, sizeof(long_pri_pkcs8), NULL, 0, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
DO(ecc_import_pkcs8(long_pric_pkcs8, sizeof(long_pric_pkcs8), NULL, 0, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
DO(ecc_import_pkcs8(short_pri_pkcs8, sizeof(short_pri_pkcs8), NULL, 0, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
DO(ecc_import_pkcs8(short_pric_pkcs8, sizeof(short_pric_pkcs8), NULL, 0, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
/* import - private PKCS8 format - password protected (PBES1 algorithms) */
#ifdef LTC_MD2
DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md2_des, sizeof(long_pri_pkcs8_pbe_md2_des), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#ifdef LTC_MD5
DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md5_des, sizeof(long_pri_pkcs8_pbe_md5_des), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#ifdef LTC_SHA1
DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_sha1_des, sizeof(long_pri_pkcs8_pbe_sha1_des), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_RC2) && defined(LTC_MD2)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md2_rc2_64, sizeof(long_pri_pkcs8_pbe_md2_rc2_64), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_RC2) && defined(LTC_MD5)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md5_rc2_64, sizeof(long_pri_pkcs8_pbe_md5_rc2_64), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_RC2) && defined(LTC_SHA1)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_sha1_rc2_64, sizeof(long_pri_pkcs8_pbe_sha1_rc2_64), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
/* import - private PKCS8 format - password protected (PBES2 algorithms) */
#if defined(LTC_RC2)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_rc2_cbc, sizeof(long_pri_pkcs8_pbkdf2_rc2_cbc), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_DES)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_des_cbc, sizeof(long_pri_pkcs8_pbkdf2_des_cbc), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_DES)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_des_ede3_cbc), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_SHA224) && defined(LTC_DES)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_sha224_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_sha224_des_ede3_cbc), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_SHA256) && defined(LTC_DES)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_sha256_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_sha256_des_ede3_cbc), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_SHA384) && defined(LTC_DES)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_sha384_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_sha384_des_ede3_cbc), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
#if defined(LTC_SHA512) && defined(LTC_DES)
DO(ecc_import_pkcs8(long_pri_pkcs8_pbkdf2_sha512_des_ede3_cbc, sizeof(long_pri_pkcs8_pbkdf2_sha512_des_ede3_cbc), "secret", 6, &key));
DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key));
DO(s_ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
#endif
/* import - X.509 EC certificates */
DO(ecc_import_x509(x509_cert_long, sizeof(x509_cert_long), &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
DO(ecc_import_x509(x509_cert_longc, sizeof(x509_cert_longc), &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
DO(ecc_import_x509(x509_cert_short, sizeof(x509_cert_short), &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
DO(ecc_import_x509(x509_cert_shortc, sizeof(x509_cert_shortc), &key));
DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key));
DO(s_ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
/* export - openssl compatible DER format */
@ -1487,7 +1487,7 @@ static int _ecc_import_export(void) {
}
#ifdef LTC_ECC_SHAMIR
static int _ecc_test_recovery(void)
static int s_ecc_test_recovery(void)
{
int i, recid, stat;
const ltc_ecc_curve* dp;
@ -1526,13 +1526,13 @@ static int _ecc_test_recovery(void)
DO(ecc_set_curve(dp, &reckey));
stat = ecc_recover_key(eth_sig, sizeof(eth_sig)-1, eth_hash, sizeof(eth_hash), 0, LTC_ECCSIG_RFC7518, &reckey);
if (stat != CRYPT_OK) return CRYPT_FAIL_TESTVECTOR;
DO(_ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
DO(s_ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
ecc_free(&reckey);
DO(ecc_set_curve(dp, &reckey));
stat = ecc_recover_key(eth_sig, sizeof(eth_sig), eth_hash, sizeof(eth_hash), -1, LTC_ECCSIG_ETH27, &reckey);
if (stat != CRYPT_OK) return CRYPT_FAIL_TESTVECTOR;
DO(_ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
DO(s_ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
ecc_free(&reckey);
ecc_free(&pubkey);
@ -1577,7 +1577,7 @@ static int _ecc_test_recovery(void)
DO(ecc_set_curve(dp, &reckey));
stat = ecc_recover_key(buf, len, data16, 16, recid, LTC_ECCSIG_RFC7518, &reckey);
if (stat != CRYPT_OK) return CRYPT_FAIL_TESTVECTOR;
DO(_ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
DO(s_ecc_key_cmp(PK_PUBLIC, &pubkey, &reckey));
/* cleanup */
ecc_free(&reckey);
@ -1593,15 +1593,15 @@ int ecc_test(void)
{
if (ltc_mp.name == NULL) return CRYPT_NOP;
DO(_ecc_old_api()); /* up to 1.18 */
DO(_ecc_new_api());
DO(_ecc_import_export());
DO(_ecc_test_mp());
DO(_ecc_issue108());
DO(_ecc_issue443_447());
DO(s_ecc_old_api()); /* up to 1.18 */
DO(s_ecc_new_api());
DO(s_ecc_import_export());
DO(s_ecc_test_mp());
DO(s_ecc_issue108());
DO(s_ecc_issue443_447());
#ifdef LTC_ECC_SHAMIR
DO(_ecc_test_shamir());
DO(_ecc_test_recovery());
DO(s_ecc_test_shamir());
DO(s_ecc_test_recovery());
#endif
return CRYPT_OK;
}

View File

@ -9,7 +9,7 @@
#ifdef LTC_CURVE25519
static int _rfc_8410_10_test(void)
static int s_rfc_8410_10_test(void)
{
const struct {
const char* b64;
@ -89,7 +89,7 @@ typedef struct {
const char* signature;
} rfc_8032_7_1_t;
static int _rfc_8032_7_1_test(void)
static int s_rfc_8032_7_1_test(void)
{
const rfc_8032_7_1_t rfc_8032_7_1[] = {
{
@ -233,10 +233,10 @@ int ed25519_test(void)
if (ltc_mp.name == NULL) return CRYPT_NOP;
if ((ret = _rfc_8410_10_test()) != CRYPT_OK) {
if ((ret = s_rfc_8410_10_test()) != CRYPT_OK) {
return ret;
}
if ((ret = _rfc_8032_7_1_test()) != CRYPT_OK) {
if ((ret = s_rfc_8032_7_1_test()) != CRYPT_OK) {
return ret;
}

View File

@ -3,7 +3,7 @@
#include <tomcrypt_test.h>
#if defined(LTC_MPI)
static int _radix_to_bin_test(void)
static int s_radix_to_bin_test(void)
{
/* RADIX 16 */
const char *ghex = "2";
@ -128,7 +128,7 @@ static int _radix_to_bin_test(void)
int mpi_test(void)
{
if (ltc_mp.name == NULL) return CRYPT_NOP;
return _radix_to_bin_test();
return s_radix_to_bin_test();
}
#else
int mpi_test(void)

View File

@ -15,21 +15,21 @@ struct padding_testcase_ {
cmp_padding_testcase cmp;
};
#define EQ(a, b) _eq((a), (b), #a, #b)
#define EQ(a, b) s_eq((a), (b), #a, #b)
static int _eq(unsigned long a, unsigned long b, const char* _a, const char* _b)
static int s_eq(unsigned long a, unsigned long b, const char* s_a, const char* s_b)
{
if (a == b) return CRYPT_OK;
#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
else fprintf(stderr, "'%s == %s' failed, %lu is not equal to %lu\n", _a, _b, a, b);
else fprintf(stderr, "'%s == %s' failed, %lu is not equal to %lu\n", s_a, s_b, a, b);
#else
LTC_UNUSED_PARAM(_a);
LTC_UNUSED_PARAM(_b);
LTC_UNUSED_PARAM(s_a);
LTC_UNUSED_PARAM(s_b);
#endif
return CRYPT_FAIL_TESTVECTOR;
}
static int _cmp_pkcs7(const padding_testcase* t, const unsigned char* p, unsigned long len)
static int s_cmp_pkcs7(const padding_testcase* t, const unsigned char* p, unsigned long len)
{
unsigned long n, diff = len - t->is;
DOX(EQ(len, t->should), t->name);
@ -40,7 +40,7 @@ static int _cmp_pkcs7(const padding_testcase* t, const unsigned char* p, unsigne
}
#ifdef LTC_RNG_GET_BYTES
static int _cmp_iso_10126(const padding_testcase* t, const unsigned char* p, unsigned long len)
static int s_cmp_iso_10126(const padding_testcase* t, const unsigned char* p, unsigned long len)
{
LTC_UNUSED_PARAM(p);
if (len < t->should || len > t->max) {
@ -54,7 +54,7 @@ static int _cmp_iso_10126(const padding_testcase* t, const unsigned char* p, uns
}
#endif
static int _cmp_x923(const padding_testcase* t, const unsigned char* p, unsigned long len)
static int s_cmp_x923(const padding_testcase* t, const unsigned char* p, unsigned long len)
{
unsigned long n, diff = len - t->is;
DOX(EQ(len, t->should), t->name);
@ -65,7 +65,7 @@ static int _cmp_x923(const padding_testcase* t, const unsigned char* p, unsigned
return CRYPT_OK;
}
static int _cmp_oaz(const padding_testcase* t, const unsigned char* p, unsigned long len)
static int s_cmp_oaz(const padding_testcase* t, const unsigned char* p, unsigned long len)
{
unsigned long n, diff = len - t->is;
DOX(EQ(len, t->should), t->name);
@ -78,7 +78,7 @@ static int _cmp_oaz(const padding_testcase* t, const unsigned char* p, unsigned
return CRYPT_OK;
}
static int _cmp_zero(const padding_testcase* t, const unsigned char* p, unsigned long len)
static int s_cmp_zero(const padding_testcase* t, const unsigned char* p, unsigned long len)
{
unsigned long n, diff = len - t->is;
DOX(EQ(len, t->should), t->name);
@ -88,7 +88,7 @@ static int _cmp_zero(const padding_testcase* t, const unsigned char* p, unsigned
return CRYPT_OK;
}
static int _padding_testrun(const padding_testcase* t)
static int s_padding_testrun(const padding_testcase* t)
{
unsigned long len;
unsigned char buf[1024];
@ -105,47 +105,47 @@ static int _padding_testrun(const padding_testcase* t)
int padding_test(void)
{
const padding_testcase cases[] = {
{ 0, 16, 0, LTC_PAD_PKCS7 | 16, "0-pkcs7", _cmp_pkcs7 },
{ 1, 16, 0, LTC_PAD_PKCS7 | 16, "1-pkcs7", _cmp_pkcs7 },
{ 15, 16, 0, LTC_PAD_PKCS7 | 16, "15-pkcs7", _cmp_pkcs7 },
{ 16, 32, 0, LTC_PAD_PKCS7 | 16, "16-pkcs7", _cmp_pkcs7 },
{ 255, 256, 0, LTC_PAD_PKCS7 | 16, "255-pkcs7", _cmp_pkcs7 },
{ 256, 272, 0, LTC_PAD_PKCS7 | 16, "256-pkcs7", _cmp_pkcs7 },
{ 0, 16, 0, LTC_PAD_PKCS7 | 16, "0-pkcs7", s_cmp_pkcs7 },
{ 1, 16, 0, LTC_PAD_PKCS7 | 16, "1-pkcs7", s_cmp_pkcs7 },
{ 15, 16, 0, LTC_PAD_PKCS7 | 16, "15-pkcs7", s_cmp_pkcs7 },
{ 16, 32, 0, LTC_PAD_PKCS7 | 16, "16-pkcs7", s_cmp_pkcs7 },
{ 255, 256, 0, LTC_PAD_PKCS7 | 16, "255-pkcs7", s_cmp_pkcs7 },
{ 256, 272, 0, LTC_PAD_PKCS7 | 16, "256-pkcs7", s_cmp_pkcs7 },
#ifdef LTC_RNG_GET_BYTES
{ 0, 16, 256, LTC_PAD_ISO_10126 | 16, "0-rand", _cmp_iso_10126 },
{ 1, 16, 272, LTC_PAD_ISO_10126 | 16, "1-rand", _cmp_iso_10126 },
{ 15, 16, 272, LTC_PAD_ISO_10126 | 16, "15-rand", _cmp_iso_10126 },
{ 16, 32, 288, LTC_PAD_ISO_10126 | 16, "16-rand", _cmp_iso_10126 },
{ 255, 256, 512, LTC_PAD_ISO_10126 | 16, "255-rand", _cmp_iso_10126 },
{ 256, 272, 528, LTC_PAD_ISO_10126 | 16, "256-rand", _cmp_iso_10126 },
{ 0, 16, 256, LTC_PAD_ISO_10126 | 16, "0-rand", s_cmp_iso_10126 },
{ 1, 16, 272, LTC_PAD_ISO_10126 | 16, "1-rand", s_cmp_iso_10126 },
{ 15, 16, 272, LTC_PAD_ISO_10126 | 16, "15-rand", s_cmp_iso_10126 },
{ 16, 32, 288, LTC_PAD_ISO_10126 | 16, "16-rand", s_cmp_iso_10126 },
{ 255, 256, 512, LTC_PAD_ISO_10126 | 16, "255-rand", s_cmp_iso_10126 },
{ 256, 272, 528, LTC_PAD_ISO_10126 | 16, "256-rand", s_cmp_iso_10126 },
#endif
{ 0, 16, 0, LTC_PAD_ANSI_X923 | 16, "0-x923", _cmp_x923 },
{ 1, 16, 0, LTC_PAD_ANSI_X923 | 16, "1-x923", _cmp_x923 },
{ 15, 16, 0, LTC_PAD_ANSI_X923 | 16, "15-x923", _cmp_x923 },
{ 16, 32, 0, LTC_PAD_ANSI_X923 | 16, "16-x923", _cmp_x923 },
{ 255, 256, 0, LTC_PAD_ANSI_X923 | 16, "255-x923", _cmp_x923 },
{ 256, 272, 0, LTC_PAD_ANSI_X923 | 16, "256-x923", _cmp_x923 },
{ 0, 16, 0, LTC_PAD_ANSI_X923 | 16, "0-x923", s_cmp_x923 },
{ 1, 16, 0, LTC_PAD_ANSI_X923 | 16, "1-x923", s_cmp_x923 },
{ 15, 16, 0, LTC_PAD_ANSI_X923 | 16, "15-x923", s_cmp_x923 },
{ 16, 32, 0, LTC_PAD_ANSI_X923 | 16, "16-x923", s_cmp_x923 },
{ 255, 256, 0, LTC_PAD_ANSI_X923 | 16, "255-x923", s_cmp_x923 },
{ 256, 272, 0, LTC_PAD_ANSI_X923 | 16, "256-x923", s_cmp_x923 },
{ 0, 16, 0, LTC_PAD_ONE_AND_ZERO | 16, "0-one-and-zero", _cmp_oaz },
{ 1, 16, 0, LTC_PAD_ONE_AND_ZERO | 16, "1-one-and-zero", _cmp_oaz },
{ 15, 16, 0, LTC_PAD_ONE_AND_ZERO | 16, "15-one-and-zero", _cmp_oaz },
{ 16, 32, 0, LTC_PAD_ONE_AND_ZERO | 16, "16-one-and-zero", _cmp_oaz },
{ 255, 256, 0, LTC_PAD_ONE_AND_ZERO | 16, "255-one-and-zero", _cmp_oaz },
{ 256, 272, 0, LTC_PAD_ONE_AND_ZERO | 16, "256-one-and-zero", _cmp_oaz },
{ 0, 16, 0, LTC_PAD_ONE_AND_ZERO | 16, "0-one-and-zero", s_cmp_oaz },
{ 1, 16, 0, LTC_PAD_ONE_AND_ZERO | 16, "1-one-and-zero", s_cmp_oaz },
{ 15, 16, 0, LTC_PAD_ONE_AND_ZERO | 16, "15-one-and-zero", s_cmp_oaz },
{ 16, 32, 0, LTC_PAD_ONE_AND_ZERO | 16, "16-one-and-zero", s_cmp_oaz },
{ 255, 256, 0, LTC_PAD_ONE_AND_ZERO | 16, "255-one-and-zero", s_cmp_oaz },
{ 256, 272, 0, LTC_PAD_ONE_AND_ZERO | 16, "256-one-and-zero", s_cmp_oaz },
{ 0, 0, 0, LTC_PAD_ZERO | 16, "0-zero", _cmp_zero },
{ 1, 16, 0, LTC_PAD_ZERO | 16, "1-zero", _cmp_zero },
{ 15, 16, 0, LTC_PAD_ZERO | 16, "15-zero", _cmp_zero },
{ 16, 16, 0, LTC_PAD_ZERO | 16, "16-zero", _cmp_zero },
{ 255, 256, 0, LTC_PAD_ZERO | 16, "255-zero", _cmp_zero },
{ 256, 256, 0, LTC_PAD_ZERO | 16, "256-zero", _cmp_zero },
{ 0, 0, 0, LTC_PAD_ZERO | 16, "0-zero", s_cmp_zero },
{ 1, 16, 0, LTC_PAD_ZERO | 16, "1-zero", s_cmp_zero },
{ 15, 16, 0, LTC_PAD_ZERO | 16, "15-zero", s_cmp_zero },
{ 16, 16, 0, LTC_PAD_ZERO | 16, "16-zero", s_cmp_zero },
{ 255, 256, 0, LTC_PAD_ZERO | 16, "255-zero", s_cmp_zero },
{ 256, 256, 0, LTC_PAD_ZERO | 16, "256-zero", s_cmp_zero },
{ 0, 16, 0, LTC_PAD_ZERO_ALWAYS | 16, "0-zero-always", _cmp_zero },
{ 1, 16, 0, LTC_PAD_ZERO_ALWAYS | 16, "1-zero-always", _cmp_zero },
{ 15, 16, 0, LTC_PAD_ZERO_ALWAYS | 16, "15-zero-always", _cmp_zero },
{ 16, 32, 0, LTC_PAD_ZERO_ALWAYS | 16, "16-zero-always", _cmp_zero },
{ 255, 256, 0, LTC_PAD_ZERO_ALWAYS | 16, "255-zero-always", _cmp_zero },
{ 256, 272, 0, LTC_PAD_ZERO_ALWAYS | 16, "256-zero-always", _cmp_zero },
{ 0, 16, 0, LTC_PAD_ZERO_ALWAYS | 16, "0-zero-always", s_cmp_zero },
{ 1, 16, 0, LTC_PAD_ZERO_ALWAYS | 16, "1-zero-always", s_cmp_zero },
{ 15, 16, 0, LTC_PAD_ZERO_ALWAYS | 16, "15-zero-always", s_cmp_zero },
{ 16, 32, 0, LTC_PAD_ZERO_ALWAYS | 16, "16-zero-always", s_cmp_zero },
{ 255, 256, 0, LTC_PAD_ZERO_ALWAYS | 16, "255-zero-always", s_cmp_zero },
{ 256, 272, 0, LTC_PAD_ZERO_ALWAYS | 16, "256-zero-always", s_cmp_zero },
};
unsigned i;
/* Examples from https://en.wikipedia.org/w/index.php?title=Padding_(cryptography)&oldid=823057951#Byte_padding */
@ -170,7 +170,7 @@ int padding_test(void)
unsigned long l;
for (i = 0; i < sizeof(cases)/sizeof(cases[0]); ++i) {
DOX(_padding_testrun(&cases[i]), cases[i].name);
DOX(s_padding_testrun(&cases[i]), cases[i].name);
}
for (i = 0; i < sizeof(tv)/sizeof(tv[0]); ++i) {

View File

@ -173,8 +173,8 @@ static const unsigned char openssl_rsautl_pkcs[] = {
0xef, 0x57, 0x23, 0x4b, 0x3a, 0xa3, 0x24, 0x91, 0x4d, 0xfb, 0xb2, 0xd4, 0xe7, 0x5e, 0x41, 0x7e,
};
extern const char _der_tests_cacert_root_cert[];
extern const unsigned long _der_tests_cacert_root_cert_size;
extern const char ltc_der_tests_cacert_root_cert[];
extern const unsigned long ltc_der_tests_cacert_root_cert_size;
static int rsa_compat_test(void)
{
@ -269,7 +269,7 @@ static int rsa_compat_test(void)
return 0;
}
static int _rsa_key_cmp(const int should_type, const rsa_key *should, const rsa_key *is)
static int s_rsa_key_cmp(const int should_type, const rsa_key *should, const rsa_key *is)
{
if(should_type != is->type)
return CRYPT_ERROR;
@ -294,7 +294,7 @@ static int _rsa_key_cmp(const int should_type, const rsa_key *should, const rsa_
return CRYPT_OK;
}
static int _rsa_issue_301(int prng_idx)
static int s_rsa_issue_301(int prng_idx)
{
rsa_key key, key_in;
unsigned char buf[4096];
@ -306,21 +306,21 @@ static int _rsa_issue_301(int prng_idx)
DO(rsa_export(buf, &len, PK_PRIVATE, &key));
DO(rsa_import(buf, len, &key_in));
DO(_rsa_key_cmp(PK_PRIVATE, &key, &key_in));
DO(s_rsa_key_cmp(PK_PRIVATE, &key, &key_in));
rsa_free(&key_in);
len = sizeof(buf);
DO(rsa_export(buf, &len, PK_PUBLIC, &key));
DO(rsa_import(buf, len, &key_in));
DO(_rsa_key_cmp(PK_PUBLIC, &key, &key_in));
DO(s_rsa_key_cmp(PK_PUBLIC, &key, &key_in));
rsa_free(&key_in);
len = sizeof(buf);
DO(rsa_export(buf, &len, PK_PUBLIC | PK_STD, &key));
DO(rsa_import(buf, len, &key_in));
DO(_rsa_key_cmp(PK_PUBLIC, &key, &key_in));
DO(s_rsa_key_cmp(PK_PUBLIC, &key, &key_in));
rsa_free(&key_in);
rsa_free(&key);
@ -328,7 +328,7 @@ static int _rsa_issue_301(int prng_idx)
}
#ifdef LTC_TEST_READDIR
static int _rsa_import_x509(const void *in, unsigned long inlen, void *key)
static int s_rsa_import_x509(const void *in, unsigned long inlen, void *key)
{
/* here we use the filesize as indicator for the rsa size
* that would fail to import for tfm because it's fixed-size
@ -343,7 +343,7 @@ static int _rsa_import_x509(const void *in, unsigned long inlen, void *key)
}
#if defined(LTC_MD2) && defined(LTC_MD5) && defined(LTC_RC2)
static int _rsa_import_pkcs8(const void *in, unsigned long inlen, void *key)
static int s_rsa_import_pkcs8(const void *in, unsigned long inlen, void *key)
{
return rsa_import_pkcs8(in, inlen, "secret", 6, key);
}
@ -376,13 +376,13 @@ int rsa_test(void)
}
#ifdef LTC_TEST_READDIR
DO(test_process_dir("tests/rsa", &key, _rsa_import_x509, (dir_cleanup_cb)rsa_free, "rsa_test"));
DO(test_process_dir("tests/rsa", &key, s_rsa_import_x509, (dir_cleanup_cb)rsa_free, "rsa_test"));
#if defined(LTC_MD2) && defined(LTC_MD5) && defined(LTC_RC2)
DO(test_process_dir("tests/rsa-pkcs8", &key, _rsa_import_pkcs8, (dir_cleanup_cb)rsa_free, "rsa_pkcs8_test"));
DO(test_process_dir("tests/rsa-pkcs8", &key, s_rsa_import_pkcs8, (dir_cleanup_cb)rsa_free, "rsa_pkcs8_test"));
#endif
#endif
DO(_rsa_issue_301(prng_idx));
DO(s_rsa_issue_301(prng_idx));
/* make 10 random key */
for (cnt = 0; cnt < 10; cnt++) {
@ -695,7 +695,7 @@ print_hex("q", tmp, len);
rsa_free(&key);
len3 = sizeof(tmp);
DO(base64_decode(_der_tests_cacert_root_cert, _der_tests_cacert_root_cert_size, tmp, &len3));
DO(base64_decode(ltc_der_tests_cacert_root_cert, ltc_der_tests_cacert_root_cert_size, tmp, &len3));
DO(rsa_import_x509(tmp, len3, &key));

View File

@ -51,7 +51,7 @@ static const unsigned char nlist3[] = {0x00, 0x00, 0x00, 0x09, 0x7a, 0x6c, 0x69,
LTC_SSH encoding test
@return CRYPT_OK if successful
*/
static int _ssh_encoding_test(void)
static int s_ssh_encoding_test(void)
{
unsigned char buffer[BUFSIZE];
unsigned long buflen;
@ -190,7 +190,7 @@ static int _ssh_encoding_test(void)
LTC_SSH decoding test
@return CRYPT_OK if successful
*/
static int _ssh_decoding_test(void)
static int s_ssh_decoding_test(void)
{
char strbuf[BUFSIZE];
void *u, *v;
@ -339,8 +339,8 @@ int ssh_test(void)
{
if (ltc_mp.name == NULL) return CRYPT_NOP;
DO(_ssh_encoding_test());
DO(_ssh_decoding_test());
DO(s_ssh_encoding_test());
DO(s_ssh_decoding_test());
return CRYPT_OK;
}

View File

@ -103,7 +103,7 @@ static void *run(void *arg)
/*
* unregister ciphers, hashes & prngs
*/
static void _unregister_all(void)
static void s_unregister_all(void)
{
#ifdef LTC_RIJNDAEL
#ifdef ENCRYPT_ONLY
@ -275,13 +275,13 @@ static void _unregister_all(void)
#ifdef LTC_SPRNG
unregister_prng(&sprng_desc);
#endif
} /* _cleanup() */
} /* s_cleanup() */
static void register_algs(void)
{
int err;
atexit(_unregister_all);
atexit(s_unregister_all);
#ifndef LTC_YARROW
#error This demo requires Yarrow.

View File

@ -1,8 +1,8 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef __TEST_H_
#define __TEST_H_
#ifndef TOMCRYPT_TEST_H_
#define TOMCRYPT_TEST_H_
#include "tomcrypt_private.h"

View File

@ -9,7 +9,7 @@
#ifdef LTC_CURVE25519
static int _rfc_7748_5_2_test(void)
static int s_rfc_7748_5_2_test(void)
{
/* RFC 7748 Ch. 5.2 */
const struct {
@ -58,7 +58,7 @@ static int _rfc_7748_5_2_test(void)
return CRYPT_OK;
}
static int _rfc_7748_6_test(void)
static int s_rfc_7748_6_test(void)
{
/* RFC 7748 Ch. 6 */
const unsigned char alice_private[] = {
@ -111,7 +111,7 @@ static int _rfc_7748_6_test(void)
return CRYPT_OK;
}
static int _rfc_8410_10_test(void)
static int s_rfc_8410_10_test(void)
{
const struct {
const char *b64;
@ -139,11 +139,11 @@ static int _rfc_8410_10_test(void)
return CRYPT_OK;
}
static int _x25519_pkcs8_test(void)
static int s_x25519_pkcs8_test(void)
{
const struct {
const char *b64, *pass;
} _x25519_pkcs8[] = {
} s_x25519_pkcs8[] = {
/* `openssl genpkey -algorithm x25519 -pass stdin -aes128` */
{
"MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjG5kRkEihOvQICCAAw"
@ -162,18 +162,18 @@ static int _x25519_pkcs8_test(void)
curve25519_key key;
unsigned char buf[1024];
unsigned long buflen, passlen;
for (n = 0; n < sizeof(_x25519_pkcs8)/sizeof(_x25519_pkcs8[0]); ++n) {
for (n = 0; n < sizeof(s_x25519_pkcs8)/sizeof(s_x25519_pkcs8[0]); ++n) {
buflen = sizeof(buf);
DO(base64_decode(_x25519_pkcs8[n].b64, XSTRLEN(_x25519_pkcs8[n].b64), buf, &buflen));
if (_x25519_pkcs8[n].pass != NULL) passlen = XSTRLEN(_x25519_pkcs8[n].pass);
DO(base64_decode(s_x25519_pkcs8[n].b64, XSTRLEN(s_x25519_pkcs8[n].b64), buf, &buflen));
if (s_x25519_pkcs8[n].pass != NULL) passlen = XSTRLEN(s_x25519_pkcs8[n].pass);
else passlen = 0;
DO(x25519_import_pkcs8(buf, buflen, _x25519_pkcs8[n].pass, passlen, &key));
DO(x25519_import_pkcs8(buf, buflen, s_x25519_pkcs8[n].pass, passlen, &key));
zeromem(buf, sizeof(buf));
}
return CRYPT_OK;
}
static int _x25519_compat_test(void)
static int s_x25519_compat_test(void)
{
curve25519_key priv, pub, imported;
unsigned char buf[1024];
@ -221,19 +221,19 @@ int x25519_test(void)
if (ltc_mp.name == NULL) return CRYPT_NOP;
if ((ret = _rfc_7748_5_2_test()) != CRYPT_OK) {
if ((ret = s_rfc_7748_5_2_test()) != CRYPT_OK) {
return ret;
}
if ((ret = _rfc_7748_6_test()) != CRYPT_OK) {
if ((ret = s_rfc_7748_6_test()) != CRYPT_OK) {
return ret;
}
if ((ret = _rfc_8410_10_test()) != CRYPT_OK) {
if ((ret = s_rfc_8410_10_test()) != CRYPT_OK) {
return ret;
}
if ((ret = _x25519_pkcs8_test()) != CRYPT_OK) {
if ((ret = s_x25519_pkcs8_test()) != CRYPT_OK) {
return ret;
}
if ((ret = _x25519_compat_test()) != CRYPT_OK) {
if ((ret = s_x25519_compat_test()) != CRYPT_OK) {
return ret;
}