Main Page Modules Data Structures File List Data Fields Globals Related Pages

# beecrypt/dlpk.c

Go to the documentation of this file.

    00001
    00007 /*
    00008  * Copyright (c) 2000, 2001 Virtual Unlimited B.V.
    00009  *
    00010  * Author: Bob Deblier <bob@virtualunlimited.com>
    00011  *
    00012  * This library is free software; you can redistribute it and/or
    00013  * modify it under the terms of the GNU Lesser General Public
    00014  * License as published by the Free Software Foundation; either
    00015  * version 2.1 of the License, or (at your option) any later version.
    00016  *
    00017  * This library is distributed in the hope that it will be useful,
    00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00020  * Lesser General Public License for more details.
    00021  *
    00022  * You should have received a copy of the GNU Lesser General Public
    00023  * License along with this library; if not, write to the Free Software
    00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00025  *
    00026  */
    00027
    00028 #include "system.h"
    00029 #include "dlpk.h"
    00030 #include "mp32.h"
    00031 #include "debug.h"
    00032
    00033 int dlpk_pInit(dlpk_p* pk)
    00034 {
    00035         if (dldp_pInit(&pk->param) < 0)
    00036                 return -1;
    00037
    00038         mp32nzero(&pk->y);
    00039
    00040         return 0;
    00041 }
    00042
    00043 int dlpk_pFree(dlpk_p* pk)
    00044 {
    00045         /*@-usereleased -compdef @*/ /* pk->param.{p,q,n}.modl is OK */
    00046         if (dldp_pFree(&pk->param) < 0)
    00047                 return -1;
    00048
    00049         mp32nfree(&pk->y);
    00050
    00051         return 0;
    00052         /*@=usereleased =compdef @*/
    00053 }
    00054
    00055 int dlpk_pCopy(dlpk_p* dst, const dlpk_p* src)
    00056 {
    00057         if (dldp_pCopy(&dst->param, &src->param) < 0)
    00058                 return -1;
    00059
    00060         mp32ncopy(&dst->y, &src->y);
    00061
    00062         return 0;
    00063 }
    00064
    00065 int dlpk_pEqual(const dlpk_p* a, const dlpk_p* b)
    00066 {
    00067         return dldp_pEqual(&a->param, &b->param) &&
    00068                 mp32eqx(a->y.size, a->y.data, b->y.size, b->y.data);
    00069 }
    00070
    00071 int dlpk_pgoqValidate(const dlpk_p* pk, randomGeneratorContext* rgc, int cofactor)
    00072 {
    00073         register int rc = dldp_pgoqValidate(&pk->param, rgc, cofactor);
    00074
    00075         if (rc <= 0)
    00076                 return rc;
    00077
    00078         if (mp32leone(pk->y.size, pk->y.data))
    00079                 return 0;
    00080
    00081         if (mp32gex(pk->y.size, pk->y.data, pk->param.p.size, pk->param.p.modl))
    00082                 return 0;
    00083
    00084         return 1;
    00085 }
    00086
    00087 int dlpk_pgonValidate(const dlpk_p* pk, randomGeneratorContext* rgc)
    00088 {
    00089         register int rc = dldp_pgonValidate(&pk->param, rgc);
    00090
    00091         if (rc <= 0)
    00092                 return rc;
    00093
    00094         if (mp32leone(pk->y.size, pk->y.data))
    00095                 return 0;
    00096
    00097         if (mp32gex(pk->y.size, pk->y.data, pk->param.p.size, pk->param.p.modl))
    00098                 return 0;
    00099
    00100         return 1;
    00101 }