renaming rc4+sober128 stream API to *_stream_*
This commit is contained in:
parent
28835a513f
commit
dd35e86c60
@ -966,11 +966,11 @@ typedef struct {
|
||||
unsigned char buf[256];
|
||||
} rc4_state;
|
||||
|
||||
int rc4_setup(rc4_state *st, const unsigned char *key, unsigned long keylen);
|
||||
int rc4_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
|
||||
int rc4_keystream(rc4_state *st, unsigned char *out, unsigned long outlen);
|
||||
int rc4_stream_setup(rc4_state *st, const unsigned char *key, unsigned long keylen);
|
||||
int rc4_stream_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
|
||||
int rc4_stream_keystream(rc4_state *st, unsigned char *out, unsigned long outlen);
|
||||
int rc4_stream_done(rc4_state *st);
|
||||
int rc4_test(void);
|
||||
int rc4_stream_test(void);
|
||||
|
||||
#endif /* LTC_RC4_STREAM */
|
||||
|
||||
@ -984,12 +984,12 @@ typedef struct {
|
||||
int nbuf; /* number of part-word stream bits buffered */
|
||||
} sober128_state;
|
||||
|
||||
int sober128_setup(sober128_state *st, const unsigned char *key, unsigned long keylen);
|
||||
int sober128_setiv(sober128_state *st, const unsigned char *iv, unsigned long ivlen);
|
||||
int sober128_crypt(sober128_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
|
||||
int sober128_keystream(sober128_state *st, unsigned char *out, unsigned long outlen);
|
||||
int sober128_stream_setup(sober128_state *st, const unsigned char *key, unsigned long keylen);
|
||||
int sober128_stream_setiv(sober128_state *st, const unsigned char *iv, unsigned long ivlen);
|
||||
int sober128_stream_crypt(sober128_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
|
||||
int sober128_stream_keystream(sober128_state *st, unsigned char *out, unsigned long outlen);
|
||||
int sober128_stream_done(sober128_state *st);
|
||||
int sober128_test(void);
|
||||
int sober128_stream_test(void);
|
||||
|
||||
#endif /* LTC_SOBER128_STREAM */
|
||||
|
||||
|
@ -66,12 +66,12 @@ int rc4_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *pr
|
||||
LTC_MUTEX_LOCK(&prng->lock);
|
||||
if (prng->ready) {
|
||||
/* rc4_ready() was already called, do "rekey" operation */
|
||||
if ((err = rc4_keystream(&prng->rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
if ((err = rc4_stream_keystream(&prng->rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
for(i = 0; i < inlen; i++) buf[i % sizeof(buf)] ^= in[i];
|
||||
/* initialize RC4 */
|
||||
if ((err = rc4_setup(&prng->rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
if ((err = rc4_stream_setup(&prng->rc4.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
/* drop first 3072 bytes - https://en.wikipedia.org/wiki/RC4#Fluhrer.2C_Mantin_and_Shamir_attack */
|
||||
for (i = 0; i < 12; i++) rc4_keystream(&prng->rc4.s, buf, sizeof(buf));
|
||||
for (i = 0; i < 12; i++) rc4_stream_keystream(&prng->rc4.s, buf, sizeof(buf));
|
||||
}
|
||||
else {
|
||||
/* rc4_ready() was not called yet, add entropy to the buffer */
|
||||
@ -101,9 +101,9 @@ int rc4_ready(prng_state *prng)
|
||||
XMEMCPY(buf, prng->rc4.s.buf, sizeof(buf));
|
||||
/* initialize RC4 */
|
||||
len = MIN(prng->rc4.s.x, 256); /* TODO: we can perhaps always use all 256 bytes */
|
||||
if ((err = rc4_setup(&prng->rc4.s, buf, len)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
if ((err = rc4_stream_setup(&prng->rc4.s, buf, len)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
/* drop first 3072 bytes - https://en.wikipedia.org/wiki/RC4#Fluhrer.2C_Mantin_and_Shamir_attack */
|
||||
for (i = 0; i < 12; i++) rc4_keystream(&prng->rc4.s, buf, sizeof(buf));
|
||||
for (i = 0; i < 12; i++) rc4_stream_keystream(&prng->rc4.s, buf, sizeof(buf));
|
||||
prng->ready = 1;
|
||||
LBL_UNLOCK:
|
||||
LTC_MUTEX_UNLOCK(&prng->lock);
|
||||
@ -122,7 +122,7 @@ unsigned long rc4_read(unsigned char *out, unsigned long outlen, prng_state *prn
|
||||
if (outlen == 0 || prng == NULL || out == NULL) return 0;
|
||||
LTC_MUTEX_LOCK(&prng->lock);
|
||||
if (!prng->ready) { outlen = 0; goto LBL_UNLOCK; }
|
||||
if (rc4_keystream(&prng->rc4.s, out, outlen) != CRYPT_OK) outlen = 0;
|
||||
if (rc4_stream_keystream(&prng->rc4.s, out, outlen) != CRYPT_OK) outlen = 0;
|
||||
LBL_UNLOCK:
|
||||
LTC_MUTEX_UNLOCK(&prng->lock);
|
||||
return outlen;
|
||||
|
@ -66,12 +66,12 @@ int sober128_add_entropy(const unsigned char *in, unsigned long inlen, prng_stat
|
||||
LTC_MUTEX_LOCK(&prng->lock);
|
||||
if (prng->ready) {
|
||||
/* sober128_ready() was already called, do "rekey" operation */
|
||||
if ((err = sober128_keystream(&prng->sober128.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
if ((err = sober128_stream_keystream(&prng->sober128.s, buf, sizeof(buf))) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
for(i = 0; i < inlen; i++) buf[i % sizeof(buf)] ^= in[i];
|
||||
/* key 32 bytes, 20 rounds */
|
||||
if ((err = sober128_setup(&prng->sober128.s, buf, 32)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
if ((err = sober128_stream_setup(&prng->sober128.s, buf, 32)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
/* iv 8 bytes */
|
||||
if ((err = sober128_setiv(&prng->sober128.s, buf + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
if ((err = sober128_stream_setiv(&prng->sober128.s, buf + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
/* clear KEY + IV */
|
||||
XMEMSET(buf, 0, sizeof(buf));
|
||||
}
|
||||
@ -97,11 +97,11 @@ int sober128_ready(prng_state *prng)
|
||||
LTC_ARGCHK(prng != NULL);
|
||||
|
||||
LTC_MUTEX_LOCK(&prng->lock);
|
||||
if (prng->ready) { err = CRYPT_OK; goto LBL_UNLOCK; }
|
||||
if (prng->ready) { err = CRYPT_OK; goto LBL_UNLOCK; }
|
||||
/* key 32 bytes, 20 rounds */
|
||||
if ((err = sober128_setup(&prng->sober128.s, prng->sober128.ent, 32)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
if ((err = sober128_stream_setup(&prng->sober128.s, prng->sober128.ent, 32)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
/* iv 8 bytes */
|
||||
if ((err = sober128_setiv(&prng->sober128.s, prng->sober128.ent + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
if ((err = sober128_stream_setiv(&prng->sober128.s, prng->sober128.ent + 32, 8)) != CRYPT_OK) goto LBL_UNLOCK;
|
||||
XMEMSET(&prng->sober128.ent, 0, sizeof(prng->sober128.ent));
|
||||
prng->sober128.idx = 0;
|
||||
prng->ready = 1;
|
||||
@ -122,7 +122,7 @@ unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state
|
||||
if (outlen == 0 || prng == NULL || out == NULL) return 0;
|
||||
LTC_MUTEX_LOCK(&prng->lock);
|
||||
if (!prng->ready) { outlen = 0; goto LBL_UNLOCK; }
|
||||
if (sober128_keystream(&prng->sober128.s, out, outlen) != CRYPT_OK) outlen = 0;
|
||||
if (sober128_stream_keystream(&prng->sober128.s, out, outlen) != CRYPT_OK) outlen = 0;
|
||||
LBL_UNLOCK:
|
||||
LTC_MUTEX_UNLOCK(&prng->lock);
|
||||
return outlen;
|
||||
|
@ -18,7 +18,7 @@
|
||||
@param keylen The length of the secret key (8 - 256 bytes)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int rc4_setup(rc4_state *st, const unsigned char *key, unsigned long keylen)
|
||||
int rc4_stream_setup(rc4_state *st, const unsigned char *key, unsigned long keylen)
|
||||
{
|
||||
unsigned char tmp, *s;
|
||||
int x, y;
|
||||
@ -54,7 +54,7 @@ int rc4_setup(rc4_state *st, const unsigned char *key, unsigned long keylen)
|
||||
@param out [out] The ciphertext (or plaintext), length inlen
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int rc4_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out)
|
||||
int rc4_stream_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out)
|
||||
{
|
||||
unsigned char x, y, *s, tmp;
|
||||
|
||||
@ -84,12 +84,12 @@ int rc4_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen, unsig
|
||||
@param outlen The output length
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int rc4_keystream(rc4_state *st, unsigned char *out, unsigned long outlen)
|
||||
int rc4_stream_keystream(rc4_state *st, unsigned char *out, unsigned long outlen)
|
||||
{
|
||||
if (outlen == 0) return CRYPT_OK; /* nothing to do */
|
||||
LTC_ARGCHK(out != NULL);
|
||||
XMEMSET(out, 0, outlen);
|
||||
return rc4_crypt(st, out, outlen, out);
|
||||
return rc4_stream_crypt(st, out, outlen, out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#ifdef LTC_RC4_STREAM
|
||||
|
||||
int rc4_test(void)
|
||||
int rc4_stream_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
@ -23,10 +23,10 @@ int rc4_test(void)
|
||||
const unsigned char ct[] = { 0x75, 0xb7, 0x87, 0x80, 0x99, 0xe0, 0xc5, 0x96 };
|
||||
unsigned char buf[10];
|
||||
|
||||
if ((err = rc4_setup(&st, key, sizeof(key))) != CRYPT_OK) return err;
|
||||
if ((err = rc4_crypt(&st, pt, sizeof(pt), buf)) != CRYPT_OK) return err;
|
||||
if (XMEMCMP(buf, ct, sizeof(ct))) return CRYPT_FAIL_TESTVECTOR;
|
||||
if ((err = rc4_stream_done(&st)) != CRYPT_OK) return err;
|
||||
if ((err = rc4_stream_setup(&st, key, sizeof(key))) != CRYPT_OK) return err;
|
||||
if ((err = rc4_stream_crypt(&st, pt, sizeof(pt), buf)) != CRYPT_OK) return err;
|
||||
if (XMEMCMP(buf, ct, sizeof(ct))) return CRYPT_FAIL_TESTVECTOR;
|
||||
if ((err = rc4_stream_done(&st)) != CRYPT_OK) return err;
|
||||
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
|
@ -161,7 +161,7 @@ static void s128_diffuse(sober128_state *c)
|
||||
@param keylen The length of the secret key (octets)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int sober128_setup(sober128_state *c, const unsigned char *key, unsigned long keylen)
|
||||
int sober128_stream_setup(sober128_state *c, const unsigned char *key, unsigned long keylen)
|
||||
{
|
||||
ulong32 i, k;
|
||||
|
||||
@ -208,7 +208,7 @@ int sober128_setup(sober128_state *c, const unsigned char *key, unsigned long ke
|
||||
@param inlen The length of the IV (must be 12)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int sober128_setiv(sober128_state *c, const unsigned char *iv, unsigned long ivlen)
|
||||
int sober128_stream_setiv(sober128_state *c, const unsigned char *iv, unsigned long ivlen)
|
||||
{
|
||||
ulong32 i, k;
|
||||
|
||||
@ -253,7 +253,7 @@ int sober128_setiv(sober128_state *c, const unsigned char *iv, unsigned long ivl
|
||||
@param out [out] The ciphertext (or plaintext), length inlen
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int sober128_crypt(sober128_state *c, const unsigned char *in, unsigned long inlen, unsigned char *out)
|
||||
int sober128_stream_crypt(sober128_state *c, const unsigned char *in, unsigned long inlen, unsigned char *out)
|
||||
{
|
||||
ulong32 t;
|
||||
|
||||
@ -321,12 +321,12 @@ int sober128_crypt(sober128_state *c, const unsigned char *in, unsigned long inl
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
int sober128_keystream(sober128_state *c, unsigned char *out, unsigned long outlen)
|
||||
int sober128_stream_keystream(sober128_state *c, unsigned char *out, unsigned long outlen)
|
||||
{
|
||||
if (outlen == 0) return CRYPT_OK; /* nothing to do */
|
||||
LTC_ARGCHK(out != NULL);
|
||||
XMEMSET(out, 0, outlen);
|
||||
return sober128_crypt(c, out, outlen, out);
|
||||
return sober128_stream_crypt(c, out, outlen, out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#ifdef LTC_SOBER128
|
||||
|
||||
int sober128_test(void)
|
||||
int sober128_stream_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
@ -27,10 +27,10 @@ int sober128_test(void)
|
||||
sober128_state st;
|
||||
|
||||
XMEMSET(src, 0, len); /* input */
|
||||
if ((err = sober128_setup(&st, key, sizeof(key))) != CRYPT_OK) return err;
|
||||
if ((err = sober128_setiv(&st, iv, sizeof(iv))) != CRYPT_OK) return err;
|
||||
if ((err = sober128_crypt(&st, src, len, dst)) != CRYPT_OK) return err;
|
||||
if ((err = sober128_stream_done(&st)) != CRYPT_OK) return err;
|
||||
if ((err = sober128_stream_setup(&st, key, sizeof(key))) != CRYPT_OK) return err;
|
||||
if ((err = sober128_stream_setiv(&st, iv, sizeof(iv))) != CRYPT_OK) return err;
|
||||
if ((err = sober128_stream_crypt(&st, src, len, dst)) != CRYPT_OK) return err;
|
||||
if ((err = sober128_stream_done(&st)) != CRYPT_OK) return err;
|
||||
if (XMEMCMP(dst, out, len)) {
|
||||
#if 0
|
||||
int y;
|
||||
|
@ -19,10 +19,10 @@ int cipher_hash_test(void)
|
||||
DO(chacha_test());
|
||||
#endif
|
||||
#ifdef LTC_RC4_STREAM
|
||||
DO(rc4_test());
|
||||
DO(rc4_stream_test());
|
||||
#endif
|
||||
#ifdef LTC_SOBER128_STREAM
|
||||
DO(sober128_test());
|
||||
DO(sober128_stream_test());
|
||||
#endif
|
||||
|
||||
/* test hashes */
|
||||
|
Loading…
Reference in New Issue
Block a user