projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
MT29F NAND driver: implement bad block handling and remapping.
[bertos.git]
/
bertos
/
sec
/
prng
/
isaac.c
diff --git
a/bertos/sec/prng/isaac.c
b/bertos/sec/prng/isaac.c
index d4246f718c5e9271cec834ebdd7a6f46ba786cd2..86c162700369b8f7b99366ccef5913c8c6601d45 100644
(file)
--- a/
bertos/sec/prng/isaac.c
+++ b/
bertos/sec/prng/isaac.c
@@
-32,7
+32,7
@@
*
* \brief ISAAC implementation
* \author Giovanni Bajo <rasky@develer.com>
*
* \brief ISAAC implementation
* \author Giovanni Bajo <rasky@develer.com>
- *
+ *
*/
/*
*/
/*
@@
-48,6
+48,7
@@
MODIFIED:
#include "isaac.h"
#include <sec/prng.h>
#include "isaac.h"
#include <sec/prng.h>
+#include <sec/util.h>
#include <cfg/compiler.h>
#include <cfg/macros.h>
#include <string.h>
#include <cfg/compiler.h>
#include <cfg/macros.h>
#include <string.h>
@@
-56,7
+57,7
@@
typedef uint32_t ub4;
typedef uint16_t ub2;
typedef uint8_t ub1;
typedef uint16_t ub2;
typedef uint8_t ub1;
-#define ind(mm,x) (*(ub4 *)((
ub1 *
)(mm) + ((x) & ((CONFIG_ISAAC_RANDSIZ-1)<<2))))
+#define ind(mm,x) (*(ub4 *)((
size_t
)(mm) + ((x) & ((CONFIG_ISAAC_RANDSIZ-1)<<2))))
#define rngstep(mix,a,b,mm,m,m2,r,x) \
{ \
x = *m; \
#define rngstep(mix,a,b,mm,m,m2,r,x) \
{ \
x = *m; \
@@
-65,7
+66,7
@@
typedef uint8_t ub1;
*(r++) = b = ind(mm,y>>CONFIG_ISAAC_RANDSIZL) + x; \
}
*(r++) = b = ind(mm,y>>CONFIG_ISAAC_RANDSIZL) + x; \
}
-static void isaac(I
SAAC_
Context *ctx)
+static void isaac(I
saac
Context *ctx)
{
register ub4 a,b,x,y,*m,*mm,*m2,*r,*mend;
mm=ctx->randmem; r=ctx->randrsl;
{
register ub4 a,b,x,y,*m,*mm,*m2,*r,*mend;
mm=ctx->randmem; r=ctx->randrsl;
@@
-100,16
+101,16
@@
static void isaac(ISAAC_Context *ctx)
h^=a>>9; c+=h; a+=b; \
}
h^=a>>9; c+=h; a+=b; \
}
-static void
ISAAC
_reseed(PRNG *ctx_, const uint8_t *seed)
+static void
isaac
_reseed(PRNG *ctx_, const uint8_t *seed)
{
{
- I
SAAC_Context *ctx = (ISAAC_
Context *)ctx_;
+ I
saacContext *ctx = (Isaac
Context *)ctx_;
int i;
ub4 a,b,c,d,e,f,g,h;
ub4 *m,*r;
int i;
ub4 a,b,c,d,e,f,g,h;
ub4 *m,*r;
- //
Copy seed over half of randrsl, to reuse half of last-generated
- //
data as seed
.
-
memcpy(ctx->randrsl, seed, sizeof(ctx->randrsl)/2
);
+ //
XOR the new seed over the current state, so to depend on
+ //
the previously-generated output
.
+
xor_block(ctx->randrsl, ctx->randrsl, seed, sizeof(ctx->randrsl)
);
ctx->randa = ctx->randb = ctx->randc = 0;
m=ctx->randmem;
ctx->randa = ctx->randb = ctx->randc = 0;
m=ctx->randmem;
@@
-141,23
+142,23
@@
static void ISAAC_reseed(PRNG *ctx_, const uint8_t *seed)
}
}
}
}
-static void
ISAAC
_generate(PRNG *ctx_, uint8_t *data, size_t len)
+static void
isaac
_generate(PRNG *ctx_, uint8_t *data, size_t len)
{
{
- I
SAAC_Context *ctx = (ISAAC_
Context *)ctx_;
+ I
saacContext *ctx = (Isaac
Context *)ctx_;
STATIC_ASSERT(sizeof(ctx->randrsl) == CONFIG_ISAAC_RANDSIZ*4);
while (len)
{
ASSERT(ctx->randcnt <= CONFIG_ISAAC_RANDSIZ*4);
STATIC_ASSERT(sizeof(ctx->randrsl) == CONFIG_ISAAC_RANDSIZ*4);
while (len)
{
ASSERT(ctx->randcnt <= CONFIG_ISAAC_RANDSIZ*4);
-
+
if (ctx->randcnt == CONFIG_ISAAC_RANDSIZ*4)
{
isaac(ctx);
if (ctx->randcnt == CONFIG_ISAAC_RANDSIZ*4)
{
isaac(ctx);
- ctx->randcnt = 0;
+ ctx->randcnt = 0;
}
}
-
- size_t L = MIN(len, CONFIG_ISAAC_RANDSIZ*4 - (size_t)ctx->randcnt);
+
+ size_t L = MIN(len, CONFIG_ISAAC_RANDSIZ*4 - (size_t)ctx->randcnt);
memcpy(data, (uint8_t*)ctx->randrsl + ctx->randcnt, L);
data += L;
ctx->randcnt += L;
memcpy(data, (uint8_t*)ctx->randrsl + ctx->randcnt, L);
data += L;
ctx->randcnt += L;
@@
-168,11
+169,12
@@
static void ISAAC_generate(PRNG *ctx_, uint8_t *data, size_t len)
/**********************************************************************/
/**********************************************************************/
-void
ISAAC_init(ISAAC_
Context *ctx)
+void
isaac_init(Isaac
Context *ctx)
{
{
- ctx->prng.reseed = ISAAC_reseed;
- ctx->prng.generate = ISAAC_generate;
- ctx->prng.seed_len = sizeof(ctx->randrsl) / 2;
+ ctx->prng.reseed = isaac_reseed;
+ ctx->prng.generate = isaac_generate;
+ ctx->prng.seed_len = sizeof(ctx->randrsl);
+ ctx->prng.seeded = 0;
ctx->randcnt = CONFIG_ISAAC_RANDSIZ*4;
memset(ctx->randrsl, 0, sizeof(ctx->randrsl));
ctx->randcnt = CONFIG_ISAAC_RANDSIZ*4;
memset(ctx->randrsl, 0, sizeof(ctx->randrsl));