Skip to content

Commit

Permalink
Merge ff642bf into d8d7a83
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaeckel committed Jul 14, 2020
2 parents d8d7a83 + ff642bf commit c1bdd8f
Show file tree
Hide file tree
Showing 110 changed files with 1,108 additions and 1,117 deletions.
10 changes: 5 additions & 5 deletions demos/constants.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions demos/hashsum.c
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions demos/openssl-enc.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand Down
10 changes: 5 additions & 5 deletions demos/sizes.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions doc/crypt.tex
Expand Up @@ -560,7 +560,7 @@ \subsection{Simple Encryption Demonstration}

\begin{small}
\begin{verbatim}
struct _cipher_descriptor {
struct ltc_cipher_descriptor {
/** name of cipher */
char *name;
Expand Down Expand Up @@ -745,14 +745,14 @@ \subsection{Notes}
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}
Expand Down Expand Up @@ -2594,7 +2594,7 @@ \chapter{One-Way Cryptographic Hash Functions}
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 */
Expand Down Expand Up @@ -2753,9 +2753,9 @@ \subsection{Hash Registration}
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:
Expand Down Expand Up @@ -3824,7 +3824,7 @@ \subsection{Example}
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 */
Expand Down Expand Up @@ -3860,8 +3860,8 @@ \subsection{Example}
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
Expand Down
11 changes: 8 additions & 3 deletions helper.pl
Expand Up @@ -61,12 +61,17 @@ sub check_source {
push @{$troubles->{sizeof_no_brackets}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bsizeof\s*[^\(]/;
if ($file =~ m|src/.*\.c$| &&
$file !~ m|src/ciphers/.*\.c$| &&
$file !~ m|src/hashes/.*\.c$| &&
$file !~ m|src/math/.+_desc.c$| &&
$file !~ m|src/pk/ec25519/tweetnacl.c$| &&
$file !~ m|src/stream/sober128/sober128_stream.c$| &&
$l =~ /^static(\s+[a-zA-Z0-9_]+)+\s+([^_][a-zA-Z0-9_]+)\s*\(/) {
push @{$troubles->{staticfunc_name}}, "$lineno($2)";
$l =~ /^static(\s+[a-zA-Z0-9_]+)+\s++([^s][a-zA-Z0-9_]+)\s*\(/) {
push @{$troubles->{staticfunc_name}}, "$2";
}
if ($file =~ m|src/.*\.[ch]$| && $l =~ /^\s*#\s*define\s+(_[A-Z_][a-zA-Z0-9_]*)\b/) {
my $n = $1;
push @{$troubles->{invalid_macro_name}}, "$lineno($n)"
unless ($file eq 'src/headers/tomcrypt_cfg.h' && $n eq '__has_builtin') ||
($file eq 'src/prngs/rng_get_bytes.c' && $n eq '_WIN32_WINNT');
}
$lineno++;
}
Expand Down
10 changes: 5 additions & 5 deletions src/ciphers/aes/aes.c
Expand Up @@ -80,7 +80,7 @@ const struct ltc_cipher_descriptor aes_enc_desc =

#endif

#define __LTC_AES_TAB_C__
#define LTC_AES_TAB_C
#include "aes_tab.c"

static ulong32 setup_mix(ulong32 temp)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ciphers/aes/aes_tab.c
Expand Up @@ -15,7 +15,7 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e];
Td4[x] = Si[x].[01, 01, 01, 01];
*/

#ifdef __LTC_AES_TAB_C__
#ifdef LTC_AES_TAB_C

/**
@file aes_tab.c
Expand Down Expand Up @@ -1019,4 +1019,4 @@ static const ulong32 rcon[] = {
};
#endif

#endif /* __LTC_AES_TAB_C__ */
#endif /* LTC_AES_TAB_C */
4 changes: 2 additions & 2 deletions src/ciphers/anubis.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ciphers/blowfish.c
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 9 additions & 15 deletions src/ciphers/cast5.c
Expand Up @@ -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
Expand Down Expand Up @@ -485,35 +485,29 @@ 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;
}
#endif

#ifdef _MSC_VER
#define INLINE __inline
#else
#define INLINE
#endif

INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
LTC_INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
{
ulong32 I;
I = (Km + R);
I = ROL(I, Kr);
return ((S1[LTC_BYTE(I, 3)] ^ S2[LTC_BYTE(I,2)]) - S3[LTC_BYTE(I,1)]) + S4[LTC_BYTE(I,0)];
}

INLINE static ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
LTC_INLINE static ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
{
ulong32 I;
I = (Km ^ R);
I = ROL(I, Kr);
return ((S1[LTC_BYTE(I, 3)] - S2[LTC_BYTE(I,2)]) + S3[LTC_BYTE(I,1)]) ^ S4[LTC_BYTE(I,0)];
}

INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
LTC_INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
{
ulong32 I;
I = (Km - R);
Expand All @@ -528,7 +522,7 @@ 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
Expand Down Expand Up @@ -568,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;
}
Expand All @@ -581,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
Expand Down Expand Up @@ -621,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;
}
Expand Down

0 comments on commit c1bdd8f

Please sign in to comment.