1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-27 09:18:16 +00:00

some work

This commit is contained in:
Mirek Kratochvil 2012-03-30 14:35:02 +02:00
parent d8c4d054d3
commit 87b0968e0d
5 changed files with 64 additions and 4 deletions

@ -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 {

@ -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

@ -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;
}