gnuk/src/random.c

73 lines
1.6 KiB
C
Raw Normal View History

2010-09-04 09:44:01 +00:00
/*
2010-09-05 16:55:29 +00:00
* random.c -- get random bytes
*
2011-05-12 00:26:40 +00:00
* Copyright (C) 2010, 2011 Free Software Initiative of Japan
2010-09-05 16:55:29 +00:00
* Author: NIIBE Yutaka <gniibe@fsij.org>
*
* This file is a part of Gnuk, a GnuPG USB Token implementation.
*
* Gnuk is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnuk is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
2010-09-04 09:44:01 +00:00
*/
2010-09-05 16:55:29 +00:00
#include "config.h"
#include "ch.h"
#include "gnuk.h"
2011-10-06 07:56:08 +00:00
#include "neug.h"
#define RANDOM_BYTES_LENGTH 16
static uint32_t random_word[RANDOM_BYTES_LENGTH/sizeof (uint32_t)];
void
random_init (void)
{
int i;
neug_init (random_word, RANDOM_BYTES_LENGTH/sizeof (uint32_t));
for (i = 0; i < NEUG_PRE_LOOP; i++)
(void)neug_get (NEUG_KICK_FILLING);
2011-10-07 02:01:21 +00:00
neug_prng_reseed ();
2011-10-06 07:56:08 +00:00
}
2010-09-04 09:44:01 +00:00
2011-05-12 00:26:40 +00:00
/*
* Return pointer to random 16-byte
*/
2010-09-05 16:55:29 +00:00
const uint8_t *
random_bytes_get (void)
2010-09-04 09:44:01 +00:00
{
2011-10-06 07:56:08 +00:00
neug_wait_full ();
return (const uint8_t *)random_word;
2010-09-04 09:44:01 +00:00
}
2011-05-12 00:26:40 +00:00
/*
* Free pointer to random 16-byte
*/
2010-09-05 16:55:29 +00:00
void
random_bytes_free (const uint8_t *p)
2010-09-04 09:44:01 +00:00
{
2011-10-06 07:56:08 +00:00
(void)p;
neug_flush ();
2010-09-04 09:44:01 +00:00
}
2011-05-12 00:26:40 +00:00
/*
* Return 4-byte salt
*/
2010-09-05 16:55:29 +00:00
uint32_t
2011-05-12 00:26:40 +00:00
get_salt (void)
2010-09-04 09:44:01 +00:00
{
2011-10-06 07:56:08 +00:00
return neug_get (NEUG_KICK_FILLING);
2010-09-04 09:44:01 +00:00
}