Skip to content

Commit

Permalink
Merge branch 'streams-make_state_names_consistent' into develop
Browse files Browse the repository at this point in the history
This fixes #427
  • Loading branch information
sjaeckel committed Jul 10, 2018
2 parents b5009d7 + 380d1d2 commit c9c3c42
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 147 deletions.
2 changes: 1 addition & 1 deletion demos/ltcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <tomcrypt.h>

int usage(char *name)
static int NORETURN usage(char *name)
{
int x;

Expand Down
60 changes: 30 additions & 30 deletions demos/tv_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
#include "tomcrypt_private.h"

void hash_gen(void)
static void hash_gen(void)
{
unsigned char md[MAXBLOCKSIZE], *buf;
unsigned long outlen, x, y, z;
Expand Down Expand Up @@ -49,7 +49,7 @@ void hash_gen(void)
fclose(out);
}

void cipher_gen(void)
static void cipher_gen(void)
{
unsigned char *key, pt[MAXBLOCKSIZE];
unsigned long x, y, z, w;
Expand Down Expand Up @@ -124,7 +124,7 @@ void cipher_gen(void)
fclose(out);
}

void hmac_gen(void)
static void hmac_gen(void)
{
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], *input;
int x, y, z, err;
Expand Down Expand Up @@ -176,9 +176,9 @@ void hmac_gen(void)
fclose(out);
}

void omac_gen(void)
{
#ifdef LTC_OMAC
static void omac_gen(void)
{
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
int err, x, y, z, kl;
FILE *out;
Expand Down Expand Up @@ -234,12 +234,12 @@ void omac_gen(void)
fprintf(out, "\n");
}
fclose(out);
#endif
}
#endif

void pmac_gen(void)
{
#ifdef LTC_PMAC
static void pmac_gen(void)
{
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
int err, x, y, z, kl;
FILE *out;
Expand Down Expand Up @@ -295,12 +295,12 @@ void pmac_gen(void)
fprintf(out, "\n");
}
fclose(out);
#endif
}
#endif

void eax_gen(void)
{
#ifdef LTC_EAX_MODE
static void eax_gen(void)
{
int err, kl, x, y1, z;
FILE *out;
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2],
Expand Down Expand Up @@ -361,12 +361,12 @@ void eax_gen(void)
fprintf(out, "\n");
}
fclose(out);
#endif
}
#endif

void ocb_gen(void)
{
#ifdef LTC_OCB_MODE
static void ocb_gen(void)
{
int err, kl, x, y1, z;
FILE *out;
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
Expand Down Expand Up @@ -430,12 +430,12 @@ void ocb_gen(void)
fprintf(out, "\n");
}
fclose(out);
#endif
}
#endif

void ocb3_gen(void)
{
#ifdef LTC_OCB3_MODE
static void ocb3_gen(void)
{
int err, kl, x, y1, z, noncelen;
FILE *out;
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
Expand Down Expand Up @@ -500,12 +500,12 @@ void ocb3_gen(void)
fprintf(out, "\n");
}
fclose(out);
#endif
}
#endif

void ccm_gen(void)
{
#ifdef LTC_CCM_MODE
static void ccm_gen(void)
{
int err, kl, x, y1, z;
FILE *out;
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
Expand Down Expand Up @@ -569,12 +569,12 @@ void ccm_gen(void)
fprintf(out, "\n");
}
fclose(out);
#endif
}
#endif

void gcm_gen(void)
{
#ifdef LTC_GCM_MODE
static void gcm_gen(void)
{
int err, kl, x, y1, z;
FILE *out;
unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
Expand Down Expand Up @@ -632,10 +632,10 @@ void gcm_gen(void)
fprintf(out, "\n");
}
fclose(out);
#endif
}
#endif

void base64_gen(void)
static void base64_gen(void)
{
FILE *out;
unsigned char src[32], ch;
Expand All @@ -655,11 +655,11 @@ void base64_gen(void)
fclose(out);
}

void math_gen(void)
static void math_gen(void)
{
}

void ecc_gen(void)
static void ecc_gen(void)
{
FILE *out;
unsigned char str[512];
Expand Down Expand Up @@ -701,9 +701,9 @@ void ecc_gen(void)
fclose(out);
}

void lrw_gen(void)
{
#ifdef LTC_LRW_MODE
static void lrw_gen(void)
{
FILE *out;
unsigned char tweak[16], key[16], iv[16], buf[1024];
int x, y, err;
Expand Down Expand Up @@ -765,8 +765,8 @@ void lrw_gen(void)
lrw_done(&lrw);
}
fclose(out);
#endif
}
#endif

int main(void)
{
Expand Down
12 changes: 6 additions & 6 deletions doc/crypt.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1397,30 +1397,30 @@ \chapter{Stream Ciphers}

Initialize by creating a Sosemanuk state and provide a 128- to 256-bit key to \textit{sosemanuk\_setup()}.
\begin{verbatim}
sosemanuk_state ss;
err = sosemanuk_setup(&ss, key, keylen);
sosemanuk_state st;
err = sosemanuk_setup(&st, key, keylen);
\end{verbatim}

Finish initializing with an iv of up to 128 bits.
\begin{verbatim}
err = sosemanuk_setiv(&ss, iv, ivlen);
err = sosemanuk_setiv(&st, iv, ivlen);
\end{verbatim}

For the actual encryption or decryption, call:
\begin{verbatim}
err = sosemanuk_crypt(&ss, in, inlen, out);
err = sosemanuk_crypt(&st, in, inlen, out);
\end{verbatim}

If you just want a random stream of bytes initialize the cipher with a truly random
\textit{key} (256 bits) and a truly random \textit{iv} (128 bits). After that you can
get a stream of pseudo--random bytes via:
\begin{verbatim}
err = sosemanuk_keystream(&ss, out, outlen);
err = sosemanuk_keystream(&st, out, outlen);
\end{verbatim}

When finished you should wipe the key by running \textit{sosemanuk\_done()}.
\begin{verbatim}
err = sosemanuk_done(&ss);
err = sosemanuk_done(&st);
\end{verbatim}

To do multiple encryptions and decryptions with the same key, you will want to set the iv but
Expand Down
10 changes: 5 additions & 5 deletions src/headers/tomcrypt_cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -1055,11 +1055,11 @@ typedef struct {
unsigned ptr;
} sosemanuk_state;

int sosemanuk_setup(sosemanuk_state *ss, const unsigned char *key, unsigned long keylen);
int sosemanuk_setiv(sosemanuk_state *ss, const unsigned char *iv, unsigned long ivlen);
int sosemanuk_crypt(sosemanuk_state *ss, const unsigned char *in, unsigned long inlen, unsigned char *out);
int sosemanuk_keystream(sosemanuk_state *ss, unsigned char *out, unsigned long outlen);
int sosemanuk_done(sosemanuk_state *ss);
int sosemanuk_setup(sosemanuk_state *st, const unsigned char *key, unsigned long keylen);
int sosemanuk_setiv(sosemanuk_state *st, const unsigned char *iv, unsigned long ivlen);
int sosemanuk_crypt(sosemanuk_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
int sosemanuk_keystream(sosemanuk_state *st, unsigned char *out, unsigned long outlen);
int sosemanuk_done(sosemanuk_state *st);
int sosemanuk_test(void);

#endif /* LTC_SOSEMANUK */
Expand Down

0 comments on commit c9c3c42

Please sign in to comment.