Follow new API of PolarSSL

This commit is contained in:
NIIBE Yutaka
2013-03-19 15:37:02 +09:00
parent fbcbf1b341
commit a5f4068872
5 changed files with 29 additions and 16 deletions

View File

@@ -1,7 +1,10 @@
2013-03-19 Niibe Yutaka <gniibe@fsij.org>
* src/random.c (random_gen): New (was: random_byte).
* src/call-rsa.c (rsa_sign): Follow change of API.
(modulus_calc, rsa_decrypt, rsa_verify): Likewise.
(rsa_genkey): Use random_gen.
(modulus_calc, rsa_decrypt, rsa_verify): Follow change of API.
* src/openpgp-do.c (encrypt, decrypt): Likewise.
* polarssl/include/polarssl/aes.h: Updated from PolarSSL 1.2.6.

View File

@@ -22,6 +22,7 @@
*/
#include <stdint.h>
#include <stdlib.h>
#include "random.h"
#include "bn.h"

View File

@@ -1,7 +1,7 @@
/*
* call-rsa.c -- Glue code between RSA computation and OpenPGP card protocol
*
* Copyright (C) 2010, 2011, 2012 Free Software Initiative of Japan
* Copyright (C) 2010, 2011, 2012, 2013 Free Software Initiative of Japan
* Author: NIIBE Yutaka <gniibe@fsij.org>
*
* This file is a part of Gnuk, a GnuPG USB Token implementation.
@@ -219,7 +219,7 @@ rsa_genkey (void)
return NULL;
rsa_init (&rsa_ctx, RSA_PKCS_V15, 0);
r = rsa_gen_key (&rsa_ctx, random_byte, &index,
r = rsa_gen_key (&rsa_ctx, random_gen, &index,
KEY_CONTENT_LEN * 8, RSA_EXPONENT);
if (r < 0)
{

View File

@@ -81,26 +81,35 @@ get_salt (void)
/*
* Random byte iterator
*/
uint8_t
random_byte (void *arg)
int
random_gen (void *arg, unsigned char *out, size_t out_len)
{
uint8_t *index_p = (uint8_t *)arg;
uint8_t index = *index_p;
uint8_t *p = ((uint8_t *)random_word) + index;
uint8_t v;
size_t n;
neug_wait_full ();
v = *p;
if (++index >= RANDOM_BYTES_LENGTH)
while (out_len)
{
index = 0;
neug_flush ();
neug_wait_full ();
n = RANDOM_BYTES_LENGTH - index;
if (n > out_len)
n = out_len;
memcpy (out, random_word + index, n);
out += n;
out_len -= n;
index += n;
if (index >= RANDOM_BYTES_LENGTH)
{
index = 0;
neug_flush ();
}
}
*index_p = index;
return v;
return 0;
}
#endif

View File

@@ -9,4 +9,4 @@ void random_bytes_free (const uint8_t *p);
uint32_t get_salt (void);
/* iterator returning a byta at a time */
uint8_t random_byte (void *arg);
int random_gen (void *arg, unsigned char *output, size_t output_len);