pqc/src/ntru_keypair.h

154 lines
3.8 KiB
C
Raw Normal View History

2014-05-24 21:12:15 +00:00
/*
* Copyright (C) 2014 FH Bielefeld
*
* This file is part of a FH Bielefeld project.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
2014-05-25 00:15:24 +00:00
/**
2014-06-05 13:49:40 +00:00
* @file ntru_keypair.h
* Header for internal API of ntru_keypair.c.
* @brief header for ntru_keypair.c
2014-05-25 00:15:24 +00:00
*/
2014-05-24 21:12:15 +00:00
#ifndef NTRU_KEYPAIR_H
#define NTRU_KEYPAIR_H
2014-06-05 13:49:40 +00:00
#include "ntru_params.h"
2014-05-24 21:12:15 +00:00
#include <fmpz_poly.h>
#include <fmpz.h>
#include <stdbool.h>
typedef struct keypair keypair;
2014-05-24 23:11:56 +00:00
/**
* This struct holds the keypair,
* both private and public components.
*/
2014-05-24 21:12:15 +00:00
struct keypair {
2014-05-24 23:11:56 +00:00
/**
* First part of the private key,
* a random polynom.
*/
2014-05-24 21:12:15 +00:00
fmpz_poly_t priv;
2014-05-24 23:11:56 +00:00
/**
* Second part of the private key,
* the priv polynom inverted.
*/
2014-05-24 22:58:22 +00:00
fmpz_poly_t priv_inv;
2014-05-24 23:11:56 +00:00
/**
* The public key, computed as:
* h = p * (Fq * g) mod q
*/
2014-05-24 21:12:15 +00:00
fmpz_poly_t pub;
};
2014-05-25 21:04:22 +00:00
/**
* Creates an NTRU key pair,
* consisting of public and private
* components.
*
2014-06-23 15:42:25 +00:00
* @param pair store private and public components here (the
* polynomials inside the struct will be automatically
* initialized) [out]
2014-06-28 11:11:36 +00:00
* @param f a random ternary polynomial
* @param g a random ternary polynomial
2014-06-05 13:33:57 +00:00
* @param params the NTRU context
2014-06-05 17:13:13 +00:00
* @return true for success, false if f or g are not invertible
2014-06-28 11:11:36 +00:00
* (then the caller has to try different ones)
2014-05-25 21:04:22 +00:00
*/
bool
ntru_create_keypair(
keypair *pair,
const fmpz_poly_t f,
const fmpz_poly_t g,
const ntru_params *params);
2014-05-24 21:12:15 +00:00
2014-05-30 17:23:45 +00:00
/**
* Export the public key to a file.
*
* @param filename the file to save the public key into
* @param pub the public key
2014-06-05 13:33:57 +00:00
* @param params the NTRU context
* @return true for success, false if any of the file operations failed
2014-05-30 17:23:45 +00:00
*/
bool
2014-05-30 17:23:45 +00:00
export_public_key(char const * const filename,
const fmpz_poly_t pub,
const ntru_params *params);
2014-05-30 17:23:45 +00:00
/**
* Export the private key to a file.
*
* @param filename the file to save the private key into
* @param priv the private key
2014-06-05 13:33:57 +00:00
* @param params the NTRU context
* @return true for success, false if any of the file operations failed
2014-05-30 17:23:45 +00:00
*/
bool
2014-05-30 17:23:45 +00:00
export_priv_key(char const * const filename,
const fmpz_poly_t priv,
const ntru_params *params);
2014-05-30 17:23:45 +00:00
/**
* Import the public key from a file.
*
2014-06-23 15:42:25 +00:00
* @param pub where to save the public key, must be initialized [out]
* @param filename the file to get the public key from
2014-06-05 13:33:57 +00:00
* @param params the NTRU context
* @return true for success, false if any of the file operations failed
2014-05-30 17:23:45 +00:00
*/
bool
import_public_key(fmpz_poly_t pub,
char const * const filename,
const ntru_params *params);
2014-05-30 17:23:45 +00:00
/**
* Import the private key from a file and store him
* along with his inverse.
*
2014-06-23 15:42:25 +00:00
* @param priv where to save the private key, must be initialized [out]
* @param priv_inv where to save the inverse of the private key,
* must be initialized [out]
* @param filename the file to get the private key from
2014-06-05 13:33:57 +00:00
* @param params the NTRU context
* @return true for success, false if any of the file operations failed
2014-05-30 17:23:45 +00:00
*/
bool
import_priv_key(fmpz_poly_t priv,
2014-05-30 17:23:45 +00:00
fmpz_poly_t priv_inv,
char const * const filename,
const ntru_params *params);
2014-05-30 17:23:45 +00:00
2014-05-25 21:04:22 +00:00
/**
* Used to free the inner structure
* of a keypair. This will not call free()
* on the pair itself.
*
* @param pair the pair to free the inner structure of
*/
void
ntru_delete_keypair(keypair *pair);
2014-05-25 02:06:24 +00:00
2014-05-24 21:12:15 +00:00
#endif /* NTRU_KEYPAIR_H */