Skip to content
Snippets Groups Projects
Select Git revision
  • f90e54df65b1b7fa38a1e1bfd9fae3850a4bd56d
  • 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

socket.c

Blame
    • Fredrik Hübinette (Hubbe)'s avatar
      f90e54df
      64 bittar och b{ttre bsd fd tjafs.. · f90e54df
      Fredrik Hübinette (Hubbe) authored
      Rev: lib/simulate.lpc:1.2
      Rev: src/BUGS:1.2
      Rev: src/Makefile.in:1.3
      Rev: src/array.c:1.2
      Rev: src/backend.c:1.2
      Rev: src/configure.in:1.3
      Rev: src/docode.c:1.2
      Rev: src/interpret.c:1.2
      Rev: src/language.y:1.2
      Rev: src/las.h:1.2
      Rev: src/lex.c:1.2
      Rev: src/list.c:1.2
      Rev: src/macros.h:1.2
      Rev: src/main.c:1.4
      Rev: src/mapping.c:1.2
      Rev: src/modules/files/file.c:1.2
      Rev: src/modules/files/socket.c:1.2
      Rev: src/modules/regexp/regexp.c:1.2
      Rev: src/opcodes.c:1.2
      Rev: src/port.c:1.3
      Rev: src/port.h:1.3
      Rev: src/program.c:1.2
      Rev: src/rusage.c:1.2
      Rev: src/stralloc.c:1.2
      Rev: src/stralloc.h:1.2
      Rev: src/svalue.c:1.2
      f90e54df
      History
      64 bittar och b{ttre bsd fd tjafs..
      Fredrik Hübinette (Hubbe) authored
      Rev: lib/simulate.lpc:1.2
      Rev: src/BUGS:1.2
      Rev: src/Makefile.in:1.3
      Rev: src/array.c:1.2
      Rev: src/backend.c:1.2
      Rev: src/configure.in:1.3
      Rev: src/docode.c:1.2
      Rev: src/interpret.c:1.2
      Rev: src/language.y:1.2
      Rev: src/las.h:1.2
      Rev: src/lex.c:1.2
      Rev: src/list.c:1.2
      Rev: src/macros.h:1.2
      Rev: src/main.c:1.4
      Rev: src/mapping.c:1.2
      Rev: src/modules/files/file.c:1.2
      Rev: src/modules/files/socket.c:1.2
      Rev: src/modules/regexp/regexp.c:1.2
      Rev: src/opcodes.c:1.2
      Rev: src/port.c:1.3
      Rev: src/port.h:1.3
      Rev: src/program.c:1.2
      Rev: src/rusage.c:1.2
      Rev: src/stralloc.c:1.2
      Rev: src/stralloc.h:1.2
      Rev: src/svalue.c:1.2
    der2rsa.c 3.64 KiB
    /* der2rsa.c
     *
     * Decoding of keys in PKCS#1 format.
     */
    
    /* nettle, low-level cryptographics library
     *
     * Copyright (C) 2005 Niels Möller
     *  
     * 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., 51 Franklin Street, Fifth Floor, Boston,
     * MA 02111-1301, USA.
     */
    
    #if HAVE_CONFIG_H
    # include "config.h"
    #endif
    
    #include "rsa.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
    rsa_public_key_from_der_iterator(struct rsa_public_key *pub,
    				 unsigned limit,
    				 struct asn1_der_iterator *i)
    {
      /* RSAPublicKey ::= SEQUENCE {
             modulus           INTEGER,  -- n
    	 publicExponent    INTEGER   -- e
          }
      */
    
      return (i->type == ASN1_SEQUENCE
    	  && asn1_der_decode_constructed_last(i) == ASN1_ITERATOR_PRIMITIVE
    	  && asn1_der_get_bignum(i, pub->n, limit) 
    	  && mpz_sgn(pub->n) > 0
    	  && GET(i, pub->e, limit)
    	  && asn1_der_iterator_next(i) == ASN1_ITERATOR_END
    	  && rsa_public_key_prepare(pub));
    }
    
    int
    rsa_private_key_from_der_iterator(struct rsa_public_key *pub,
    				  struct rsa_private_key *priv,
    				  unsigned limit,
    				  struct asn1_der_iterator *i)
    {
      /* RSAPrivateKey ::= SEQUENCE {
             version           Version,
    	 modulus           INTEGER,  -- n
    	 publicExponent    INTEGER,  -- e
    	 privateExponent   INTEGER,  -- d
    	 prime1            INTEGER,  -- p
    	 prime2            INTEGER,  -- q
    	 exponent1         INTEGER,  -- d mod (p-1)
    	 exponent2         INTEGER,  -- d mod (q-1)
    	 coefficient       INTEGER,  -- (inverse of q) mod p
    	 otherPrimeInfos   OtherPrimeInfos OPTIONAL
        }
      */
    
      uint32_t version;
      
      if (i->type != ASN1_SEQUENCE)
        return 0;
    
      if (asn1_der_decode_constructed_last(i) == ASN1_ITERATOR_PRIMITIVE
          && i->type == ASN1_INTEGER
          && asn1_der_get_uint32(i, &version)
          && version <= 1
          && GET(i, pub->n, limit)
          && GET(i, pub->e, limit)
          && rsa_public_key_prepare(pub)
          && GET(i, priv->d, limit)
          && GET(i, priv->p, limit)
          && GET(i, priv->q, limit)
          && GET(i, priv->a, limit)
          && GET(i, priv->b, limit)
          && GET(i, priv->c, limit)
          && rsa_private_key_prepare(priv))
        {
          if (version == 1)
    	{
    	  /* otherPrimeInfos must be present. We ignore the contents */
    	  if (!(asn1_der_iterator_next(i) == ASN1_ITERATOR_CONSTRUCTED
    		&& i->type == ASN1_SEQUENCE))
    	    return 0;
    	}
    
          return (asn1_der_iterator_next(i) == ASN1_ITERATOR_END);
        }
      
      return 0;
    }
    
    int
    rsa_keypair_from_der(struct rsa_public_key *pub,
    		     struct rsa_private_key *priv,
    		     unsigned limit, 
    		     size_t length, const uint8_t *data)
    {
      struct asn1_der_iterator i;
      enum asn1_iterator_result res;
    
      res = asn1_der_iterator_first(&i, length, data);
    
      if (res != ASN1_ITERATOR_CONSTRUCTED)
        return 0;
    
      if (priv)
        return rsa_private_key_from_der_iterator(pub, priv, limit, &i);
      else
        return rsa_public_key_from_der_iterator(pub, limit, &i);    
    }