diff --git a/src/decrypt.c b/src/decrypt.c index 1832d6e..3b67ba1 100644 --- a/src/decrypt.c +++ b/src/decrypt.c @@ -30,6 +30,7 @@ #include "decrypt.h" #include "ntru_string.h" +#include #include #include @@ -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]) { diff --git a/src/decrypt.h b/src/decrypt.h index 48b665b..beeb8ff 100644 --- a/src/decrypt.h +++ b/src/decrypt.h @@ -32,6 +32,8 @@ #include "ntru_string.h" #include "poly.h" +#include + #include #include @@ -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(