1 /*
2  * Copyright (c) 2000, 2001, 2002 X-Way Rights BV
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  */
19 
20 /*!\file dlkp.c
21  * \brief Discrete Logarithm keypair.
22  * \author Bob Deblier <bob.deblier@telenet.be>
23  * \ingroup DL_m
24  */
25 
26 #define BEECRYPT_DLL_EXPORT
27 
28 #if HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31 
32 #include "beecrypt/dlkp.h"
33 
dlkp_pPair(dlkp_p * kp,randomGeneratorContext * rgc,const dldp_p * param)34 int dlkp_pPair(dlkp_p* kp, randomGeneratorContext* rgc, const dldp_p* param)
35 {
36 	/* copy the parameters */
37 	if (dldp_pCopy(&kp->param, param) < 0)
38 		return -1;
39 
40 	if (dldp_pPair(param, rgc, &kp->x, &kp->y) < 0)
41 		return -1;
42 
43 	return 0;
44 }
45 
dlkp_pInit(dlkp_p * kp)46 int dlkp_pInit(dlkp_p* kp)
47 {
48 	if (dldp_pInit(&kp->param) < 0)
49 		return -1;
50 
51 	mpnzero(&kp->y);
52 	mpnzero(&kp->x);
53 
54 	return 0;
55 }
56 
dlkp_pFree(dlkp_p * kp)57 int dlkp_pFree(dlkp_p* kp)
58 {
59 	if (dldp_pFree(&kp->param) < 0)
60 		return -1;
61 
62 	mpnfree(&kp->y);
63 	/* wipe secret key before freeing */
64 	mpnwipe(&kp->x);
65 	mpnfree(&kp->x);
66 
67 	return 0;
68 }
69 
dlkp_pCopy(dlkp_p * dst,const dlkp_p * src)70 int dlkp_pCopy(dlkp_p* dst, const dlkp_p* src)
71 {
72 	if (dldp_pCopy(&dst->param, &src->param) < 0)
73 		return -1;
74 
75 	mpncopy(&dst->y, &src->y);
76 	mpncopy(&dst->x, &src->x);
77 
78 	return 0;
79 }
80