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 dlpk.h
21 * \brief Discrete Logarithm public key.
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/dlpk.h"
33
34 /*!\addtogroup DL_m
35 * \{
36 */
37
dlpk_pInit(dlpk_p * pk)38 int dlpk_pInit(dlpk_p* pk)
39 {
40 if (dldp_pInit(&pk->param) < 0)
41 return -1;
42
43 mpnzero(&pk->y);
44
45 return 0;
46 }
47
dlpk_pFree(dlpk_p * pk)48 int dlpk_pFree(dlpk_p* pk)
49 {
50 if (dldp_pFree(&pk->param) < 0)
51 return -1;
52
53 mpnfree(&pk->y);
54
55 return 0;
56 }
57
dlpk_pCopy(dlpk_p * dst,const dlpk_p * src)58 int dlpk_pCopy(dlpk_p* dst, const dlpk_p* src)
59 {
60 if (dldp_pCopy(&dst->param, &src->param) < 0)
61 return -1;
62
63 mpncopy(&dst->y, &src->y);
64
65 return 0;
66 }
67
dlpk_pEqual(const dlpk_p * a,const dlpk_p * b)68 int dlpk_pEqual(const dlpk_p* a, const dlpk_p* b)
69 {
70 return dldp_pEqual(&a->param, &b->param) &&
71 mpeqx(a->y.size, a->y.data, b->y.size, b->y.data);
72 }
73
dlpk_pgoqValidate(const dlpk_p * pk,randomGeneratorContext * rgc,int cofactor)74 int dlpk_pgoqValidate(const dlpk_p* pk, randomGeneratorContext* rgc, int cofactor)
75 {
76 register int rc = dldp_pgoqValidate(&pk->param, rgc, cofactor);
77
78 if (rc <= 0)
79 return rc;
80
81 if (mpleone(pk->y.size, pk->y.data))
82 return 0;
83
84 if (mpgex(pk->y.size, pk->y.data, pk->param.p.size, pk->param.p.modl))
85 return 0;
86
87 return 1;
88 }
89
dlpk_pgonValidate(const dlpk_p * pk,randomGeneratorContext * rgc)90 int dlpk_pgonValidate(const dlpk_p* pk, randomGeneratorContext* rgc)
91 {
92 register int rc = dldp_pgonValidate(&pk->param, rgc);
93
94 if (rc <= 0)
95 return rc;
96
97 if (mpleone(pk->y.size, pk->y.data))
98 return 0;
99
100 if (mpgex(pk->y.size, pk->y.data, pk->param.p.size, pk->param.p.modl))
101 return 0;
102
103 return 1;
104 }
105
106 /*!\}
107 */
108