/* * Copyright (c) 2002, 2003 Bob Deblier * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /*!\file testdldp.c * \brief Unit test program for discrete logarithm domain parameters. * \author Bob Deblier * \ingroup UNIT_m */ #include #include "beecrypt.h" #include "dldp.h" int main() { int failures = 0; dldp_p params; randomGeneratorContext rngc; dldp_pInit(¶ms); if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) { mpnumber gq; mpnzero(&gq); /* make parameters with p = 1024 bits, q = 160 bits, g of order (q) */ dldp_pgoqMake(¶ms, &rngc, 1024, 160, 1); /* we have the parameters, now see if g^q == 1 */ mpbnpowmod(¶ms.p, ¶ms.g, (mpnumber*) ¶ms.q, &gq); if (!mpisone(gq.size, gq.data)) { printf("failed test vector 1\n"); failures++; } mpnfree(&gq); dldp_pFree(¶ms); randomGeneratorContextFree(&rngc); } else { printf("random generator failure\n"); return -1; } return failures; }