diff --git a/include/codecrypt.h b/include/codecrypt.h index 6d7f2a7..ce16978 100644 --- a/include/codecrypt.h +++ b/include/codecrypt.h @@ -27,7 +27,7 @@ extern "C" { }; struct ccr_mce_privkey { - /* params */ + /* params, n and t are input params */ int n, k, t; /* goppa polynomial of degree t */ @@ -39,11 +39,11 @@ extern "C" { /* inverse of P permutation */ ccr_perm pinv; + /* systematic form permutation (inv.) */ + ccr_perm psys; + /* parity check matrix */ ccr_mtx h; - - /* TODO: also consider storing the squareroot-mod-poly mtx, - * although it's derivable from poly. */ }; struct ccr_nd_pubkey { diff --git a/lib/goppa.c b/lib/goppa.c deleted file mode 100644 index e69de29..0000000 diff --git a/lib/goppa.h b/lib/goppa.h deleted file mode 100644 index e69de29..0000000 diff --git a/lib/math.h b/lib/math.h index 96a8cb0..1026fa1 100644 --- a/lib/math.h +++ b/lib/math.h @@ -7,5 +7,10 @@ void ccr_mtx_add (int, int, ccr_mtx, ccr_mtx, ccr_mtx); void ccr_mtx_multiply (int, int, int, ccr_mtx, ccr_mtx, ccr_mtx); +int ccr_log2 (int, int*); +int ccr_gen_irred_poly (ccr_mtx, int); + +int ccr_goppa_check_mtx (ccr_mtx, int, int, ccr_mtx*, int*, int*); + #endif diff --git a/lib/mce.c b/lib/mce.c index e69de29..c2af0bc 100644 --- a/lib/mce.c +++ b/lib/mce.c @@ -0,0 +1,55 @@ + +#include "codecrypt.h" +#include "math.h" +#include "tools.h" + +int ccr_mce_gen (struct ccr_mce_pubkey* Pub, struct ccr_mce_privkey* Priv) +{ + /* params are taken from privkey matrix */ + + int ret; + int m; + ccr_mtx h; + int h_cols, h_rows; + + /* param n must be power of 2 */ + if (ccr_log2 (Priv->n, &m) ) { + ret = 1; + goto fail; + } + + /* check sanity of t param, k<=n-mt */ + if (Priv->n >= m * Priv->t) { + ret = 2; + goto fail; + } + + /* allocate space for goppa polynomial */ + Priv->poly = ccr_malloc (ccr_mtx_alloc_size (t + 1, 1) ); + if (!Priv->poly) { + ret = 3; + goto fail; + } + + /* generate the polynomial */ + if (ccr_gen_irred_poly (Priv->poly, Priv->t) ) { + ret = 4; + goto fail_free_poly; + } + + /* create canonical check matrix */ + if (ccr_goppa_check_mtx (Priv->poly, m, Priv->t, &h, &h_cols, &h_rows) ) { + ret = 5; + goto fail_free_poly; + } + + if(ccr_goppa_systematic_form(h,h_cols,h_rows, + + return 0; + +fail_free_poly: + ccr_free (Priv->poly); +fail: + return ret; +} +