Home | History | Annotate | Line # | Download | only in hcrypto
      1 /*	$NetBSD: dsa.c,v 1.2 2017/01/28 21:31:47 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2006 Kungliga Tekniska Hgskolan
      5  * (Royal Institute of Technology, Stockholm, Sweden).
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  *
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  *
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * 3. Neither the name of the Institute nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <config.h>
     37 #include <krb5/roken.h>
     38 
     39 #include <dsa.h>
     40 
     41 /*
     42  *
     43  */
     44 
     45 DSA *
     46 DSA_new(void)
     47 {
     48     DSA *dsa = calloc(1, sizeof(*dsa));
     49     dsa->meth = rk_UNCONST(DSA_get_default_method());
     50     dsa->references = 1;
     51     return dsa;
     52 }
     53 
     54 void
     55 DSA_free(DSA *dsa)
     56 {
     57     if (dsa->references <= 0)
     58 	abort();
     59 
     60     if (--dsa->references > 0)
     61 	return;
     62 
     63     (*dsa->meth->finish)(dsa);
     64 
     65 #define free_if(f) if (f) { BN_free(f); }
     66     free_if(dsa->p);
     67     free_if(dsa->q);
     68     free_if(dsa->g);
     69     free_if(dsa->pub_key);
     70     free_if(dsa->priv_key);
     71     free_if(dsa->kinv);
     72     free_if(dsa->r);
     73 #undef free_if
     74 
     75     memset(dsa, 0, sizeof(*dsa));
     76     free(dsa);
     77 
     78 }
     79 
     80 int
     81 DSA_up_ref(DSA *dsa)
     82 {
     83     return ++dsa->references;
     84 }
     85 
     86 /*
     87  *
     88  */
     89 
     90 static const DSA_METHOD dsa_null_method = {
     91     "hcrypto null DSA",
     92     NULL,
     93     NULL,
     94     NULL,
     95     NULL,
     96     NULL,
     97     NULL,
     98     NULL,
     99     0,
    100     NULL
    101 };
    102 
    103 const DSA_METHOD *
    104 DSA_null_method(void)
    105 {
    106     return &dsa_null_method;
    107 }
    108 
    109 
    110 const DSA_METHOD *dsa_default_mech = &dsa_null_method;
    111 
    112 void
    113 DSA_set_default_method(const DSA_METHOD *mech)
    114 {
    115     dsa_default_mech = mech;
    116 }
    117 
    118 const DSA_METHOD *
    119 DSA_get_default_method(void)
    120 {
    121     return dsa_default_mech;
    122 }
    123 
    124 int
    125 DSA_verify(int type, const unsigned char * digest, int digest_len,
    126 	   const unsigned char *sig, int sig_len, DSA *dsa)
    127 {
    128     return -1;
    129 }
    130