Skip to content

Commit 91a1031

Browse files
authored
Merge pull request #296 from libtom/cleanup/3
General clean-up 3
2 parents a278f72 + ea43d9a commit 91a1031

10 files changed

Lines changed: 32 additions & 18 deletions

File tree

coverage_more.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
./sizes
66
./constants
77

8-
for i in $(for j in $(echo $(./hashsum -h | tail -n +3)); do echo $j; done | sort); do echo -n "$i: " && ./hashsum -a $i tests/test.key ; done > hashsum_tv.txt
8+
for i in $(for j in $(echo $(./hashsum -h | awk '/Algorithms/,EOF' | tail -n +2)); do echo $j; done | sort); do echo -n "$i: " && ./hashsum -a $i tests/test.key ; done > hashsum_tv.txt
99
difftroubles=$(diff -i -w -B hashsum_tv.txt notes/hashsum_tv.txt | grep '^<') || true
1010
if [ -n "$difftroubles" ]; then
1111
echo "FAILURE: hashsum_tv.tx"

demos/hashsum.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,28 @@
3838

3939
static char* hashsum;
4040

41+
static void cleanup(void)
42+
{
43+
free(hashsum);
44+
}
45+
4146
static void die(int status)
4247
{
4348
unsigned long w, x;
4449
FILE* o = status == EXIT_SUCCESS ? stdout : stderr;
45-
fprintf(o, "usage: %s -a algorithm [-c] [file...]\n", hashsum);
46-
fprintf(o, "Algorithms:\n");
50+
fprintf(o, "usage: %s -a algorithm [-c] [file...]\n\n", hashsum);
51+
fprintf(o, "\t-c\tCheck the hash(es) of the file(s) written in [file].\n");
52+
fprintf(o, "\t\t(-a not required)\n");
53+
fprintf(o, "\nAlgorithms:\n\t");
4754
w = 0;
4855
for (x = 0; hash_descriptor[x].name != NULL; x++) {
4956
w += fprintf(o, "%-14s", hash_descriptor[x].name);
5057
if (w >= 70) {
51-
fprintf(o, "\n");
58+
fprintf(o, "\n\t");
5259
w = 0;
5360
}
5461
}
5562
if (w != 0) fprintf(o, "\n");
56-
free(hashsum);
5763
exit(status);
5864
}
5965

@@ -173,6 +179,7 @@ int main(int argc, char **argv)
173179
unsigned char hash_buffer[MAXBLOCKSIZE];
174180

175181
hashsum = strdup(basename(argv[0]));
182+
atexit(cleanup);
176183

177184
/* You need to register algorithms before using them */
178185
register_all_ciphers();

demos/openssl-enc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ union paddable {
8989
* Output: <no return>
9090
* Side Effects: print messages and barf (does exit(3))
9191
*/
92-
void barf(char *pname, char *err)
92+
void barf(const char *pname, const char *err)
9393
{
9494
printf("Usage: %s <enc|dec> infile outfile passphrase [salt]\n", pname);
9595
printf("\n");

src/headers/tomcrypt_custom.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@
500500
#if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_MKAT)
501501
/* Include the MPI functionality? (required by the PK algorithms) */
502502
#define LTC_MPI
503+
504+
#ifndef LTC_PK_MAX_RETRIES
505+
/* iterations limit for retry-loops */
506+
#define LTC_PK_MAX_RETRIES 20
507+
#endif
503508
#endif
504509

505510
#ifdef LTC_MRSA

src/headers/tomcrypt_pk.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ enum {
1717
/* Indicates standard output formats that can be read e.g. by OpenSSL or GnuTLS */
1818
#define PK_STD 0x1000
1919

20-
/* iterations limit for retry-loops */
21-
#define PK_MAX_RETRIES 20
22-
2320
int rand_prime(void *N, long len, prng_state *prng, int wprng);
2421

2522
#ifdef LTC_SOURCE

src/headers/tomcrypt_pkcs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,21 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
8080
/* ===> PKCS #5 -- Password Based Cryptography <=== */
8181
#ifdef LTC_PKCS_5
8282

83-
/* Algorithm #1 (old) */
83+
/* Algorithm #1 (PBKDF1) */
8484
int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
8585
const unsigned char *salt,
8686
int iteration_count, int hash_idx,
8787
unsigned char *out, unsigned long *outlen);
8888

89-
/* Algorithm #1 - OpenSSL-compatible variant for arbitrarily-long keys.
89+
/* Algorithm #1 (PBKDF1) - OpenSSL-compatible variant for arbitrarily-long keys.
9090
Compatible with EVP_BytesToKey() */
9191
int pkcs_5_alg1_openssl(const unsigned char *password,
9292
unsigned long password_len,
9393
const unsigned char *salt,
9494
int iteration_count, int hash_idx,
9595
unsigned char *out, unsigned long *outlen);
9696

97-
/* Algorithm #2 (new) */
97+
/* Algorithm #2 (PBKDF2) */
9898
int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
9999
const unsigned char *salt, unsigned long salt_len,
100100
int iteration_count, int hash_idx,

src/misc/crypt/crypt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ const char *crypt_build_settings =
301301
" SOBER128\n"
302302
#endif
303303

304-
"\nPK Algs:\n"
304+
"\nPK Crypto:\n"
305305
#if defined(LTC_MRSA)
306306
" RSA"
307307
#if defined(LTC_RSA_BLINDING) && defined(LTC_RSA_CRT_HARDENING)
@@ -329,6 +329,9 @@ const char *crypt_build_settings =
329329
#if defined(LTC_MKAT)
330330
" Katja\n"
331331
#endif
332+
#if defined(LTC_PK_MAX_RETRIES)
333+
" "NAME_VALUE(LTC_PK_MAX_RETRIES)"\n"
334+
#endif
332335

333336
"\nMPI (Math):\n"
334337
#if defined(LTC_MPI)

src/pk/dh/dh_generate_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int dh_generate_key(prng_state *prng, int wprng, dh_key *key)
4646
{
4747
unsigned char *buf;
4848
unsigned long keysize;
49-
int err, max_iterations = PK_MAX_RETRIES;
49+
int err, max_iterations = LTC_PK_MAX_RETRIES;
5050

5151
LTC_ARGCHK(key != NULL);
5252
LTC_ARGCHK(ltc_mp.name != NULL);

src/pk/ecc/ecc_sign_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen,
2222
{
2323
ecc_key pubkey;
2424
void *r, *s, *e, *p;
25-
int err, max_iterations = PK_MAX_RETRIES;
25+
int err, max_iterations = LTC_PK_MAX_RETRIES;
2626
unsigned long pbits, pbytes, i, shift_right;
2727
unsigned char ch, buf[MAXBLOCKSIZE];
2828

src/stream/chacha/chacha_crypt.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ int chacha_crypt(chacha_state *st, const unsigned char *in, unsigned long inlen,
5757
unsigned long i, j;
5858

5959
if (inlen == 0) return CRYPT_OK; /* nothing to do */
60-
LTC_ARGCHK(st != NULL);
61-
LTC_ARGCHK(in != NULL);
62-
LTC_ARGCHK(out != NULL);
60+
61+
LTC_ARGCHK(st != NULL);
62+
LTC_ARGCHK(in != NULL);
63+
LTC_ARGCHK(out != NULL);
64+
LTC_ARGCHK(st->ivlen != 0);
6365

6466
if (st->ksleft > 0) {
6567
j = MIN(st->ksleft, inlen);

0 commit comments

Comments
 (0)