DEC: improve error handling

This commit is contained in:
hasufell 2014-05-28 20:56:43 +02:00
parent 2a6ad998ce
commit c48dad818e
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
2 changed files with 15 additions and 2 deletions

View File

@ -30,6 +30,7 @@
#include "decrypt.h"
#include "ntru_string.h"
#include <stdbool.h>
#include <string.h>
#include <fmpz_poly.h>
@ -38,7 +39,7 @@
/*------------------------------------------------------------------------*/
void
bool
ntru_decrypt_poly(
fmpz_poly_t encr_msg,
fmpz_poly_t priv_key,
@ -48,6 +49,9 @@ ntru_decrypt_poly(
{
fmpz_poly_t a;
if (!encr_msg || !priv_key || !priv_key_inv || !out_bin || !ctx)
return false;
fmpz_poly_init(a);
fmpz_poly_zero(a);
@ -57,6 +61,8 @@ ntru_decrypt_poly(
fmpz_poly_mod(out_bin, ctx->p);
fmpz_poly_clear(a);
return true;
}
/*------------------------------------------------------------------------*/
@ -72,6 +78,9 @@ ntru_decrypt_string(
string *decr_msg;
fmpz_poly_t **poly_array;
if (!encr_msg || !encr_msg->len)
return NULL;
poly_array = base64_to_poly_arr(encr_msg, ctx);
while (*poly_array[i]) {

View File

@ -32,6 +32,8 @@
#include "ntru_string.h"
#include "poly.h"
#include <stdbool.h>
#include <fmpz_poly.h>
#include <fmpz.h>
@ -47,8 +49,9 @@
* @param priv_key_inv the inverse polynome to the private key
* @param out_tern the resulting ternary polynom [out]
* @param ctx the ntru_context
* @return true/false for success/failure
*/
void
bool
ntru_decrypt_poly(
fmpz_poly_t encr_msg,
fmpz_poly_t priv_key,
@ -64,6 +67,7 @@ ntru_decrypt_poly(
* the message
* @param priv_key_inv the inverse polynome to the private key
* @param ctx the ntru_context
* @return the decrypted string or NULL on failure
*/
string *
ntru_decrypt_string(