Path: blob/main/crypto/libecc/src/examples/sig/dsa/dsa.h
34928 views
/*1* Copyright (C) 2021 - This file is part of libecc project2*3* Authors:4* Ryad BENADJILA <[email protected]>5* Arnaud EBALARD <[email protected]>6*7* This software is licensed under a dual BSD and GPL v2 license.8* See LICENSE file at the root folder of the project.9*/10#ifndef __DSA_H__11#define __DSA_H__1213/*14* NOTE: although we only need libarith for DSA as we15* manipulate a ring of integers, we include libsig for16* the hash algorithms.17*/18#include <libecc/lib_ecc_config.h>1920/* The hash algorithms wrapper */21#include "../../hash/hash.h"2223/* We define hereafter the types and functions for DSA.24* The notations are taken from NIST FIPS 186-4 and should be25* compliant with it.26*/2728/* DSA public key, composed of:29* p the DSA prime modulus30* q the DSA prime order (prime divisor of (p-1))31* g the DSA generator32* y the public key = g^x (p)33*/34typedef struct {35nn p;36nn q;37nn g;38nn y;39} dsa_pub_key;4041/* DSA private key, composed of:42* p the DSA prime modulus43* q the DSA prime order (prime divisor of (p-1))44* g the DSA generator45* x the secret key46*/47typedef struct {48nn p;49nn q;50nn g;51nn x;52} dsa_priv_key;5354ATTRIBUTE_WARN_UNUSED_RET int dsa_import_priv_key(dsa_priv_key *priv, const u8 *p, u16 plen,55const u8 *q, u16 qlen,56const u8 *g, u16 glen,57const u8 *x, u16 xlen);5859ATTRIBUTE_WARN_UNUSED_RET int dsa_import_pub_key(dsa_pub_key *pub, const u8 *p, u16 plen,60const u8 *q, u16 qlen,61const u8 *g, u16 glen,62const u8 *y, u16 ylen);6364ATTRIBUTE_WARN_UNUSED_RET int dsa_compute_pub_from_priv(dsa_pub_key *pub,65const dsa_priv_key *priv);6667ATTRIBUTE_WARN_UNUSED_RET int dsa_sign(const dsa_priv_key *priv, const u8 *msg, u32 msglen,68const u8 *nonce, u16 noncelen,69u8 *sig, u16 siglen, gen_hash_alg_type dsa_hash);7071ATTRIBUTE_WARN_UNUSED_RET int dsa_verify(const dsa_pub_key *pub, const u8 *msg, u32 msglen,72const u8 *sig, u16 siglen, gen_hash_alg_type dsa_hash);7374#endif /* __DSA_H__ */757677