Skip to content
Snippets Groups Projects
Select Git revision
  • d0d8b8174750cbbcb05e6600c4857f93ba6cb73e
  • master default protected
  • 9.0
  • 8.0
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • nt-tools
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
  • v8.0.1982
  • v8.0.1980
  • v8.0.1978
  • v8.0.1976
  • v8.0.1974
  • v8.0.1972
  • v8.0.1970
  • v8.0.1968
  • v8.0.1966
41 results

Simulate.pmod

Blame
  • der2dsa.c 3.20 KiB
    /* der2dsa.c
     *
     * Decoding of DSA keys in OpenSSL and X509.1 format.
     */
    
    /* nettle, low-level cryptographics library
     *
     * Copyright (C) 2005, 2009 Niels Mller, Magnus Holmgren
     *  
     * The nettle 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.
     * 
     * The nettle 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 the nettle library; see the file COPYING.LIB.  If not, write to
     * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
     * MA 02111-1307, USA.
     */
    
    #if HAVE_CONFIG_H
    # include "config.h"
    #endif
    
    #include "dsa.h"
    
    #include "bignum.h"
    #include "asn1.h"
    
    #define GET(i, x, l)					\
    (asn1_der_iterator_next((i)) == ASN1_ITERATOR_PRIMITIVE	\
     && (i)->type == ASN1_INTEGER				\
     && asn1_der_get_bignum((i), (x), (l))			\
     && mpz_sgn((x)) > 0)
    
    int
    dsa_params_from_der_iterator(struct dsa_public_key *pub,
    			     unsigned p_max_bits,
    			     struct asn1_der_iterator *i)
    {
      /* Dss-Parms ::= SEQUENCE {
    	 p  INTEGER,
    	 q  INTEGER,
    	 g  INTEGER
         }
      */
      return (i->type == ASN1_INTEGER
    	  && asn1_der_get_bignum(i, pub->p, p_max_bits)
    	  && mpz_sgn(pub->p) > 0
    	  && GET(i, pub->q, DSA_SHA1_Q_BITS)
    	  && GET(i, pub->g, p_max_bits)
    	  && asn1_der_iterator_next(i) == ASN1_ITERATOR_END);
    }
    
    int
    dsa_public_key_from_der_iterator(struct dsa_public_key *pub,
    				 unsigned p_max_bits,
    				 struct asn1_der_iterator *i)
    {
      /* DSAPublicKey ::= INTEGER
      */
    
      return (i->type == ASN1_INTEGER
    	  && asn1_der_get_bignum(i, pub->y, p_max_bits)
    	  && mpz_sgn(pub->y) > 0);
    }
    
    int
    dsa_openssl_private_key_from_der_iterator(struct dsa_public_key *pub,
    					  struct dsa_private_key *priv,
    					  unsigned p_max_bits,
    					  struct asn1_der_iterator *i)
    {
      /* DSAPrivateKey ::= SEQUENCE {
             version           Version,
    	 p                 INTEGER,
    	 q                 INTEGER,
    	 g                 INTEGER,
    	 pub_key           INTEGER,  -- y
    	 priv_key          INTEGER,  -- x
        }
      */
    
      uint32_t version;
      
      return (i->type == ASN1_SEQUENCE
    	  && asn1_der_decode_constructed_last(i) == ASN1_ITERATOR_PRIMITIVE
    	  && i->type == ASN1_INTEGER
    	  && asn1_der_get_uint32(i, &version)
    	  && version == 0
    	  && GET(i, pub->p, p_max_bits)
    	  && GET(i, pub->q, DSA_SHA1_Q_BITS)
    	  && GET(i, pub->g, p_max_bits)
    	  && GET(i, pub->y, p_max_bits)
    	  && GET(i, priv->x, DSA_SHA1_Q_BITS)
    	  && asn1_der_iterator_next(i) == ASN1_ITERATOR_END);
    }
    
    int
    dsa_openssl_private_key_from_der(struct dsa_public_key *pub,
    		     struct dsa_private_key *priv,
    		     unsigned p_max_bits,
    		     unsigned length, const uint8_t *data)
    {
      struct asn1_der_iterator i;
      enum asn1_iterator_result res;
    
      res = asn1_der_iterator_first(&i, length, data);
    
      return (res == ASN1_ITERATOR_CONSTRUCTED
    	  && dsa_openssl_private_key_from_der_iterator(pub, priv, p_max_bits, &i));
    }