ENC: improve error handling

This commit is contained in:
hasufell 2014-05-28 20:57:22 +02:00
parent 52c1abe8ee
commit 72d13839ee
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
2 changed files with 21 additions and 8 deletions

View File

@ -39,7 +39,7 @@
/*------------------------------------------------------------------------*/
void
bool
ntru_encrypt_poly(
fmpz_poly_t msg_bin,
fmpz_poly_t pub_key,
@ -47,8 +47,12 @@ ntru_encrypt_poly(
fmpz_poly_t out,
ntru_context *ctx)
{
/* allow aliasing */
fmpz_poly_t tmp_poly_msg;
if (!msg_bin || !pub_key || !rnd || !out || !ctx)
return false;
/* allow aliasing */
fmpz_poly_init(tmp_poly_msg);
fmpz_poly_set(tmp_poly_msg, msg_bin);
@ -77,13 +81,15 @@ ntru_encrypt_poly(
}
fmpz_poly_clear(tmp_poly_msg);
return true;
}
/*------------------------------------------------------------------------*/
string *
ntru_encrypt_string(
char *msg,
string *msg,
fmpz_poly_t pub_key,
fmpz_poly_t rnd,
ntru_context *ctx)
@ -92,14 +98,18 @@ ntru_encrypt_string(
string *enc_msg;
fmpz_poly_t **poly_array;
if (!msg || !msg->len)
return NULL;
poly_array = ascii_to_bin_poly_arr(msg, ctx);
while (*poly_array[i]) {
ntru_encrypt_poly(*poly_array[i],
if (!ntru_encrypt_poly(*poly_array[i],
pub_key,
rnd,
*poly_array[i],
ctx);
ctx))
NTRU_ABORT("failed encrypting string!\n");
i++;
}

View File

@ -33,6 +33,8 @@
#include "ntru_string.h"
#include "poly.h"
#include <stdbool.h>
#include <fmpz_poly.h>
#include <fmpz.h>
@ -58,8 +60,9 @@
* @param out the output poly which is in the range {0, q-1}
* (not ternary!) [out]
* @param ctx ntru_context the ntru context
* @return true/false for success/failure
*/
void
bool
ntru_encrypt_poly(
fmpz_poly_t msg_tern,
fmpz_poly_t pub_key,
@ -76,11 +79,11 @@ ntru_encrypt_poly(
* @param rnd the random poly (should have relatively small
* coefficients, but not restricted to {-1, 0, 1})
* @param ctx ntru_context the ntru context
* @return the newly allocated encrypted string
* @return the newly allocated encrypted string, NULL on failure
*/
string *
ntru_encrypt_string(
char *msg,
string *msg,
fmpz_poly_t pub_key,
fmpz_poly_t rnd,
ntru_context *ctx);