File: rng.c

package info (click to toggle)
python-xeddsa 0.4.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 884 kB
  • sloc: ansic: 5,442; python: 525; makefile: 5
file content (27 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <string.h>
#include "crypto_stream_salsa20.h"
#include "crypto_rng.h"

#define crypto_stream crypto_stream_salsa20
#define KEYBYTES crypto_stream_salsa20_KEYBYTES
#define NONCEBYTES crypto_stream_salsa20_NONCEBYTES
#define OUTPUTBYTES crypto_rng_OUTPUTBYTES

#if KEYBYTES != crypto_rng_KEYBYTES
  KEYBYTES mismatch!
#endif

static const unsigned char nonce[NONCEBYTES] = {0};

int crypto_rng(
        unsigned char *r, /* random output */
        unsigned char *n, /* new key */
  const unsigned char *g  /* old key */
)
{
  unsigned char x[KEYBYTES + OUTPUTBYTES];
  crypto_stream(x,sizeof x,nonce,g);
  memcpy(n,x,KEYBYTES);
  memcpy(r,x + KEYBYTES,OUTPUTBYTES);
  return 0;
}