Skip to content

Commit 40eea67

Browse files
authored
Merge pull request #534 from libtom/pr/macro-names-cleanup
Clean up macro names and static functions
2 parents d8d7a83 + 469eeaf commit 40eea67

File tree

111 files changed

+1135
-1144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1135
-1144
lines changed

demos/constants.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Larry Bugbee, February 2013
1818
*/
1919

20-
static void _print_line(const char* cmd, const char* desc)
20+
static void s_print_line(const char* cmd, const char* desc)
2121
{
2222
printf(" %-16s - %s\n", cmd, desc);
2323
}
@@ -48,10 +48,10 @@ int main(int argc, char **argv)
4848
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
4949
char* base = strdup(basename(argv[0]));
5050
printf("Usage: %s [-a] [-s name]\n\n", base);
51-
_print_line("<no argument>", "The old behavior of the demo");
52-
_print_line("-a", "Only lists all constants");
53-
_print_line("-s name", "List a single constant given as argument");
54-
_print_line("-h", "The help you're looking at");
51+
s_print_line("<no argument>", "The old behavior of the demo");
52+
s_print_line("-a", "Only lists all constants");
53+
s_print_line("-s name", "List a single constant given as argument");
54+
s_print_line("-h", "The help you're looking at");
5555
free(base);
5656
} else if (strcmp(argv[1], "-a") == 0) {
5757
char *names_list;

demos/hashsum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#endif
2525

2626
/* thanks http://stackoverflow.com/a/8198009 */
27-
#define _base(x) ((x >= '0' && x <= '9') ? '0' : \
27+
#define s_base(x) ((x >= '0' && x <= '9') ? '0' : \
2828
(x >= 'a' && x <= 'f') ? 'a' - 10 : \
2929
(x >= 'A' && x <= 'F') ? 'A' - 10 : \
3030
'\255')
31-
#define HEXOF(x) (x - _base(x))
31+
#define HEXOF(x) (x - s_base(x))
3232

3333
static char* hashsum;
3434

demos/openssl-enc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void dump_bytes(unsigned char *in, unsigned long len)
166166
* Output: number of bytes after padding resp. after unpadding
167167
* Side Effects: none
168168
*/
169-
static size_t _pkcs7_pad(union paddable *buf, size_t nb, int block_length,
169+
static size_t s_pkcs7_pad(union paddable *buf, size_t nb, int block_length,
170170
int is_padding)
171171
{
172172
unsigned long length;
@@ -224,7 +224,7 @@ int do_crypt(FILE *infd, FILE *outfd, unsigned char *key, unsigned char *iv,
224224
/* We're encrypting, so pad first (if at EOF) and then
225225
crypt */
226226
if(feof(infd))
227-
nb = _pkcs7_pad(&inbuf, nb,
227+
nb = s_pkcs7_pad(&inbuf, nb,
228228
aes_desc.block_length, 1);
229229

230230
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,
239239
return ret;
240240

241241
if(feof(infd))
242-
nb = _pkcs7_pad(&outbuf, nb,
242+
nb = s_pkcs7_pad(&outbuf, nb,
243243
aes_desc.block_length, 0);
244244
if(nb == 0)
245245
/* The file didn't decrypt correctly */

demos/sizes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
like Python - Larry Bugbee, February 2013
1616
*/
1717

18-
static void _print_line(const char* cmd, const char* desc)
18+
static void s_print_line(const char* cmd, const char* desc)
1919
{
2020
printf(" %-16s - %s\n", cmd, desc);
2121
}
@@ -44,10 +44,10 @@ int main(int argc, char **argv)
4444
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
4545
char* base = strdup(basename(argv[0]));
4646
printf("Usage: %s [-a] [-s name]\n\n", base);
47-
_print_line("<no argument>", "The old behavior of the demo");
48-
_print_line("-a", "Only lists all sizes");
49-
_print_line("-s name", "List a single size given as argument");
50-
_print_line("-h", "The help you're looking at");
47+
s_print_line("<no argument>", "The old behavior of the demo");
48+
s_print_line("-a", "Only lists all sizes");
49+
s_print_line("-s name", "List a single size given as argument");
50+
s_print_line("-h", "The help you're looking at");
5151
free(base);
5252
} else if (strcmp(argv[1], "-a") == 0) {
5353
char *sizes_list;

doc/crypt.tex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ \subsection{Simple Encryption Demonstration}
560560

561561
\begin{small}
562562
\begin{verbatim}
563-
struct _cipher_descriptor {
563+
struct ltc_cipher_descriptor {
564564
/** name of cipher */
565565
char *name;
566566
@@ -745,14 +745,14 @@ \subsection{Notes}
745745
to use a cipher with the descriptor table you must register it first using:
746746
\index{register\_cipher()}
747747
\begin{verbatim}
748-
int register_cipher(const struct _cipher_descriptor *cipher);
748+
int register_cipher(const struct ltc_cipher_descriptor *cipher);
749749
\end{verbatim}
750750
Which accepts a pointer to a descriptor and returns the index into the global descriptor table. If an error occurs such
751751
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
752752
than once it will just return the index of the first copy. To remove a cipher call:
753753
\index{unregister\_cipher()}
754754
\begin{verbatim}
755-
int unregister_cipher(const struct _cipher_descriptor *cipher);
755+
int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
756756
\end{verbatim}
757757
Which returns {\bf CRYPT\_OK} if it removes the cipher, otherwise it returns {\bf CRYPT\_ERROR}.
758758
\begin{small}
@@ -2594,7 +2594,7 @@ \chapter{One-Way Cryptographic Hash Functions}
25942594
Like the set of ciphers, the set of hashes have descriptors as well. They are stored in an array called \textit{hash\_descriptor} and
25952595
are defined by:
25962596
\begin{verbatim}
2597-
struct _hash_descriptor {
2597+
struct ltc_hash_descriptor {
25982598
char *name;
25992599
26002600
unsigned long hashsize; /* digest output size in bytes */
@@ -2753,9 +2753,9 @@ \subsection{Hash Registration}
27532753
work exactly like those of the cipher registration code. The functions are:
27542754
\index{register\_hash()} \index{unregister\_hash()}
27552755
\begin{verbatim}
2756-
int register_hash(const struct _hash_descriptor *hash);
2756+
int register_hash(const struct ltc_hash_descriptor *hash);
27572757
2758-
int unregister_hash(const struct _hash_descriptor *hash);
2758+
int unregister_hash(const struct ltc_hash_descriptor *hash);
27592759
\end{verbatim}
27602760

27612761
The following hashes are provided as of this release within the LibTomCrypt library:
@@ -3824,7 +3824,7 @@ \subsection{Example}
38243824
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
38253825
format of an element is:
38263826
\begin{verbatim}
3827-
struct _prng_descriptor {
3827+
struct ltc_prng_descriptor {
38283828
char *name;
38293829
int export_size; /* size in bytes of exported state */
38303830
@@ -3860,8 +3860,8 @@ \subsection{Example}
38603860
They are the following:
38613861
\index{register\_prng()} \index{unregister\_prng()}
38623862
\begin{verbatim}
3863-
int register_prng(const struct _prng_descriptor *prng);
3864-
int unregister_prng(const struct _prng_descriptor *prng);
3863+
int register_prng(const struct ltc_prng_descriptor *prng);
3864+
int unregister_prng(const struct ltc_prng_descriptor *prng);
38653865
\end{verbatim}
38663866

38673867
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

helper.pl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,17 @@ sub check_source {
6161
push @{$troubles->{sizeof_no_brackets}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bsizeof\s*[^\(]/;
6262
if ($file =~ m|src/.*\.c$| &&
6363
$file !~ m|src/ciphers/.*\.c$| &&
64-
$file !~ m|src/hashes/.*\.c$| &&
6564
$file !~ m|src/math/.+_desc.c$| &&
6665
$file !~ m|src/pk/ec25519/tweetnacl.c$| &&
6766
$file !~ m|src/stream/sober128/sober128_stream.c$| &&
68-
$l =~ /^static(\s+[a-zA-Z0-9_]+)+\s+([^_][a-zA-Z0-9_]+)\s*\(/) {
69-
push @{$troubles->{staticfunc_name}}, "$lineno($2)";
67+
$l =~ /^static(\s+[a-zA-Z0-9_]+)+\s++([^s][a-zA-Z0-9_]+)\s*\(/) {
68+
push @{$troubles->{staticfunc_name}}, "$2";
69+
}
70+
if ($file =~ m|src/.*\.[ch]$| && $l =~ /^\s*#\s*define\s+(_[A-Z_][a-zA-Z0-9_]*)\b/) {
71+
my $n = $1;
72+
push @{$troubles->{invalid_macro_name}}, "$lineno($n)"
73+
unless ($file eq 'src/headers/tomcrypt_cfg.h' && $n eq '__has_builtin') ||
74+
($file eq 'src/prngs/rng_get_bytes.c' && $n eq '_WIN32_WINNT');
7075
}
7176
$lineno++;
7277
}

src/ciphers/aes/aes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const struct ltc_cipher_descriptor aes_enc_desc =
8080

8181
#endif
8282

83-
#define __LTC_AES_TAB_C__
83+
#define LTC_AES_TAB_C
8484
#include "aes_tab.c"
8585

8686
static ulong32 setup_mix(ulong32 temp)
@@ -275,7 +275,7 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s
275275
@return CRYPT_OK if successful
276276
*/
277277
#ifdef LTC_CLEAN_STACK
278-
static int _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
278+
static int s_rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
279279
#else
280280
int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
281281
#endif
@@ -443,7 +443,7 @@ int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *ske
443443
#ifdef LTC_CLEAN_STACK
444444
int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
445445
{
446-
int err = _rijndael_ecb_encrypt(pt, ct, skey);
446+
int err = s_rijndael_ecb_encrypt(pt, ct, skey);
447447
burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
448448
return err;
449449
}
@@ -459,7 +459,7 @@ int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *ske
459459
@return CRYPT_OK if successful
460460
*/
461461
#ifdef LTC_CLEAN_STACK
462-
static int _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
462+
static int s_rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
463463
#else
464464
int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
465465
#endif
@@ -628,7 +628,7 @@ int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *ske
628628
#ifdef LTC_CLEAN_STACK
629629
int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
630630
{
631-
int err = _rijndael_ecb_decrypt(ct, pt, skey);
631+
int err = s_rijndael_ecb_decrypt(ct, pt, skey);
632632
burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
633633
return err;
634634
}

src/ciphers/aes/aes_tab.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e];
1515
Td4[x] = Si[x].[01, 01, 01, 01];
1616
*/
1717

18-
#ifdef __LTC_AES_TAB_C__
18+
#ifdef LTC_AES_TAB_C
1919

2020
/**
2121
@file aes_tab.c
@@ -1019,4 +1019,4 @@ static const ulong32 rcon[] = {
10191019
};
10201020
#endif
10211021

1022-
#endif /* __LTC_AES_TAB_C__ */
1022+
#endif /* LTC_AES_TAB_C */

src/ciphers/anubis.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ static const ulong32 rc[] = {
876876
@return CRYPT_OK if successful
877877
*/
878878
#ifdef LTC_CLEAN_STACK
879-
static int _anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
879+
static int s_anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
880880
#else
881881
int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
882882
#endif
@@ -1013,7 +1013,7 @@ int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
10131013
int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
10141014
{
10151015
int err;
1016-
err = _anubis_setup(key, keylen, num_rounds, skey);
1016+
err = s_anubis_setup(key, keylen, num_rounds, skey);
10171017
burn_stack(sizeof(int) * 5 + sizeof(ulong32) * (MAX_N + MAX_N + 5));
10181018
return err;
10191019
}

src/ciphers/blowfish.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ int blowfish_setup_with_data(const unsigned char *key, int keylen,
472472
@return CRYPT_OK if successful
473473
*/
474474
#ifdef LTC_CLEAN_STACK
475-
static int _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
475+
static int s_blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
476476
#else
477477
int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
478478
#endif
@@ -499,7 +499,7 @@ int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
499499
#ifdef LTC_CLEAN_STACK
500500
int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
501501
{
502-
int err = _blowfish_ecb_encrypt(pt, ct, skey);
502+
int err = s_blowfish_ecb_encrypt(pt, ct, skey);
503503
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
504504
return err;
505505
}
@@ -513,7 +513,7 @@ int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
513513
@return CRYPT_OK if successful
514514
*/
515515
#ifdef LTC_CLEAN_STACK
516-
static int _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
516+
static int s_blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
517517
#else
518518
int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
519519
#endif
@@ -560,7 +560,7 @@ int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symme
560560
#ifdef LTC_CLEAN_STACK
561561
int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
562562
{
563-
int err = _blowfish_ecb_decrypt(ct, pt, skey);
563+
int err = s_blowfish_ecb_decrypt(ct, pt, skey);
564564
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
565565
return err;
566566
}

0 commit comments

Comments
 (0)