DEC: improve error handling
This commit is contained in:
parent
2a6ad998ce
commit
c48dad818e
@ -30,6 +30,7 @@
|
|||||||
#include "decrypt.h"
|
#include "decrypt.h"
|
||||||
#include "ntru_string.h"
|
#include "ntru_string.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <fmpz_poly.h>
|
#include <fmpz_poly.h>
|
||||||
@ -38,7 +39,7 @@
|
|||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void
|
bool
|
||||||
ntru_decrypt_poly(
|
ntru_decrypt_poly(
|
||||||
fmpz_poly_t encr_msg,
|
fmpz_poly_t encr_msg,
|
||||||
fmpz_poly_t priv_key,
|
fmpz_poly_t priv_key,
|
||||||
@ -48,6 +49,9 @@ ntru_decrypt_poly(
|
|||||||
{
|
{
|
||||||
fmpz_poly_t a;
|
fmpz_poly_t a;
|
||||||
|
|
||||||
|
if (!encr_msg || !priv_key || !priv_key_inv || !out_bin || !ctx)
|
||||||
|
return false;
|
||||||
|
|
||||||
fmpz_poly_init(a);
|
fmpz_poly_init(a);
|
||||||
fmpz_poly_zero(a);
|
fmpz_poly_zero(a);
|
||||||
|
|
||||||
@ -57,6 +61,8 @@ ntru_decrypt_poly(
|
|||||||
fmpz_poly_mod(out_bin, ctx->p);
|
fmpz_poly_mod(out_bin, ctx->p);
|
||||||
|
|
||||||
fmpz_poly_clear(a);
|
fmpz_poly_clear(a);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
@ -72,6 +78,9 @@ ntru_decrypt_string(
|
|||||||
string *decr_msg;
|
string *decr_msg;
|
||||||
fmpz_poly_t **poly_array;
|
fmpz_poly_t **poly_array;
|
||||||
|
|
||||||
|
if (!encr_msg || !encr_msg->len)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
poly_array = base64_to_poly_arr(encr_msg, ctx);
|
poly_array = base64_to_poly_arr(encr_msg, ctx);
|
||||||
|
|
||||||
while (*poly_array[i]) {
|
while (*poly_array[i]) {
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#include "ntru_string.h"
|
#include "ntru_string.h"
|
||||||
#include "poly.h"
|
#include "poly.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <fmpz_poly.h>
|
#include <fmpz_poly.h>
|
||||||
#include <fmpz.h>
|
#include <fmpz.h>
|
||||||
|
|
||||||
@ -47,8 +49,9 @@
|
|||||||
* @param priv_key_inv the inverse polynome to the private key
|
* @param priv_key_inv the inverse polynome to the private key
|
||||||
* @param out_tern the resulting ternary polynom [out]
|
* @param out_tern the resulting ternary polynom [out]
|
||||||
* @param ctx the ntru_context
|
* @param ctx the ntru_context
|
||||||
|
* @return true/false for success/failure
|
||||||
*/
|
*/
|
||||||
void
|
bool
|
||||||
ntru_decrypt_poly(
|
ntru_decrypt_poly(
|
||||||
fmpz_poly_t encr_msg,
|
fmpz_poly_t encr_msg,
|
||||||
fmpz_poly_t priv_key,
|
fmpz_poly_t priv_key,
|
||||||
@ -64,6 +67,7 @@ ntru_decrypt_poly(
|
|||||||
* the message
|
* the message
|
||||||
* @param priv_key_inv the inverse polynome to the private key
|
* @param priv_key_inv the inverse polynome to the private key
|
||||||
* @param ctx the ntru_context
|
* @param ctx the ntru_context
|
||||||
|
* @return the decrypted string or NULL on failure
|
||||||
*/
|
*/
|
||||||
string *
|
string *
|
||||||
ntru_decrypt_string(
|
ntru_decrypt_string(
|
||||||
|
Loading…
Reference in New Issue
Block a user