Created framework for BLISS post-quantum signature algorithm

This commit is contained in:
Andreas Steffen
2014-11-29 14:51:14 +01:00
parent 4ef819a379
commit 9d5b91d198
12 changed files with 663 additions and 8 deletions
@@ -0,0 +1,207 @@
/*
* Copyright (C) 2014 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "bliss_private_key.h"
typedef struct private_bliss_private_key_t private_bliss_private_key_t;
/**
* Private data of a bliss_private_key_t object.
*/
struct private_bliss_private_key_t {
/**
* Public interface for this signer.
*/
bliss_private_key_t public;
/**
* BLISS type
*/
u_int key_size;
/**
* reference count
*/
refcount_t ref;
};
METHOD(private_key_t, get_type, key_type_t,
private_bliss_private_key_t *this)
{
return KEY_BLISS;
}
METHOD(private_key_t, sign, bool,
private_bliss_private_key_t *this, signature_scheme_t scheme,
chunk_t data, chunk_t *signature)
{
switch (scheme)
{
case SIGN_BLISS_I_SHA256:
return FALSE;
case SIGN_BLISS_IV_SHA384:
return FALSE;
default:
DBG1(DBG_LIB, "signature scheme %N not supported with BLISS",
signature_scheme_names, scheme);
return FALSE;
}
}
METHOD(private_key_t, decrypt, bool,
private_bliss_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "encryption scheme %N not supported",
encryption_scheme_names, scheme);
return FALSE;
}
METHOD(private_key_t, get_keysize, int,
private_bliss_private_key_t *this)
{
return this->key_size;
}
METHOD(private_key_t, get_public_key, public_key_t*,
private_bliss_private_key_t *this)
{
public_key_t *public = NULL;
return public;
}
METHOD(private_key_t, get_encoding, bool,
private_bliss_private_key_t *this, cred_encoding_type_t type,
chunk_t *encoding)
{
bool success = TRUE;
*encoding = chunk_empty;
return success;
}
METHOD(private_key_t, get_fingerprint, bool,
private_bliss_private_key_t *this, cred_encoding_type_t type, chunk_t *fp)
{
bool success = FALSE;
return success;
}
METHOD(private_key_t, get_ref, private_key_t*,
private_bliss_private_key_t *this)
{
ref_get(&this->ref);
return &this->public.key;
}
METHOD(private_key_t, destroy, void,
private_bliss_private_key_t *this)
{
if (ref_put(&this->ref))
{
free(this);
}
}
/**
* Internal generic constructor
*/
static private_bliss_private_key_t *bliss_private_key_create_empty(void)
{
private_bliss_private_key_t *this;
INIT(this,
.public = {
.key = {
.get_type = _get_type,
.sign = _sign,
.decrypt = _decrypt,
.get_keysize = _get_keysize,
.get_public_key = _get_public_key,
.equals = private_key_equals,
.belongs_to = private_key_belongs_to,
.get_fingerprint = _get_fingerprint,
.has_fingerprint = private_key_has_fingerprint,
.get_encoding = _get_encoding,
.get_ref = _get_ref,
.destroy = _destroy,
},
},
.ref = 1,
);
return this;
}
/**
* See header.
*/
bliss_private_key_t *bliss_private_key_gen(key_type_t type, va_list args)
{
private_bliss_private_key_t *this;
u_int key_size = 1;
while (TRUE)
{
switch (va_arg(args, builder_part_t))
{
case BUILD_KEY_SIZE:
key_size = va_arg(args, u_int);
continue;
case BUILD_END:
break;
default:
return NULL;
}
break;
}
/* Only BLISS-I and BLISS-IV are supported */
if (key_size != 1 && key_size != 4)
{
return NULL;
}
this = bliss_private_key_create_empty();
this->key_size = key_size;
return &this->public;
}
/**
* See header.
*/
bliss_private_key_t *bliss_private_key_load(key_type_t type, va_list args)
{
private_bliss_private_key_t *this;
while (TRUE)
{
switch (va_arg(args, builder_part_t))
{
default:
return NULL;
}
break;
}
this = bliss_private_key_create_empty();
return &this->public;
}