Skip to content
Snippets Groups Projects
Select Git revision
  • 1989e827df834d89c4f20c90756aee02d8debc33
  • master default protected
  • streebog
  • gost28147
  • master-updates
  • ed448
  • shake256
  • curve448
  • ecc-sqrt
  • gosthash94cp
  • cmac64
  • block16-refactor
  • siv-mode
  • cmac-layout
  • delete-des-compat
  • delete-rsa_blind
  • aes-struct-layout
  • release-3.4-fixes
  • struct-layout
  • attribute-deprecated
  • rename-data-symbols
  • nettle_3.5.1_release_20190627
  • nettle_3.5_release_20190626
  • nettle_3.5rc1
  • nettle_3.4.1_release_20181204
  • nettle_3.4.1rc1
  • nettle_3.4_release_20171119
  • nettle_3.4rc2
  • nettle_3.4rc1
  • nettle_3.3_release_20161001
  • nettle_3.2_release_20160128
  • nettle_3.1.1_release_20150424
  • nettle_3.1_release_20150407
  • nettle_3.1rc3
  • nettle_3.1rc2
  • nettle_3.1rc1
  • nettle_3.0_release_20140607
  • nettle_2.7.1_release_20130528
  • nettle_2.7_release_20130424
  • nettle_2.6_release_20130116
  • nettle_2.5_release_20120707
41 results

hmac.h

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    • Niels Möller's avatar
      4fd20960
      * New name mangling, to reduce the risk of link collisions. All · 4fd20960
      Niels Möller authored
      functions (except memxor) now use a nettle_ or _nettle prefix when
      seen by the linker. For most functions, the header file that declares
      a function also use #define to provide a shorter more readable name
      without the prefix.
      
      Rev: src/nettle/aes-internal.h:1.9
      Rev: src/nettle/aes.h:1.6
      Rev: src/nettle/arcfour.h:1.4
      Rev: src/nettle/base16.h:1.2
      Rev: src/nettle/base64.h:1.12
      Rev: src/nettle/blowfish.h:1.8
      Rev: src/nettle/cast128.h:1.4
      Rev: src/nettle/cbc.h:1.4
      Rev: src/nettle/des.h:1.8
      Rev: src/nettle/dsa.h:1.7
      Rev: src/nettle/hmac.h:1.5
      Rev: src/nettle/knuth-lfib.h:1.2
      Rev: src/nettle/md5-compat.h:1.2
      Rev: src/nettle/md5.h:1.6
      Rev: src/nettle/pgp.h:1.2
      Rev: src/nettle/pkcs1.h:1.2
      Rev: src/nettle/rsa-compat.h:1.3
      Rev: src/nettle/rsa.h:1.22
      Rev: src/nettle/serpent.h:1.6
      Rev: src/nettle/sexp.h:1.15
      Rev: src/nettle/sha.h:1.3
      Rev: src/nettle/twofish.h:1.5
      Rev: src/nettle/yarrow.h:1.10
      4fd20960
      History
      * New name mangling, to reduce the risk of link collisions. All
      Niels Möller authored
      functions (except memxor) now use a nettle_ or _nettle prefix when
      seen by the linker. For most functions, the header file that declares
      a function also use #define to provide a shorter more readable name
      without the prefix.
      
      Rev: src/nettle/aes-internal.h:1.9
      Rev: src/nettle/aes.h:1.6
      Rev: src/nettle/arcfour.h:1.4
      Rev: src/nettle/base16.h:1.2
      Rev: src/nettle/base64.h:1.12
      Rev: src/nettle/blowfish.h:1.8
      Rev: src/nettle/cast128.h:1.4
      Rev: src/nettle/cbc.h:1.4
      Rev: src/nettle/des.h:1.8
      Rev: src/nettle/dsa.h:1.7
      Rev: src/nettle/hmac.h:1.5
      Rev: src/nettle/knuth-lfib.h:1.2
      Rev: src/nettle/md5-compat.h:1.2
      Rev: src/nettle/md5.h:1.6
      Rev: src/nettle/pgp.h:1.2
      Rev: src/nettle/pkcs1.h:1.2
      Rev: src/nettle/rsa-compat.h:1.3
      Rev: src/nettle/rsa.h:1.22
      Rev: src/nettle/serpent.h:1.6
      Rev: src/nettle/sexp.h:1.15
      Rev: src/nettle/sha.h:1.3
      Rev: src/nettle/twofish.h:1.5
      Rev: src/nettle/yarrow.h:1.10
    rsa-compat.c 3.65 KiB
    /* rsa-compat.c
     *
     * The RSA publickey algorithm, RSAREF compatible interface.
     */
    
    /* nettle, low-level cryptographics library
     *
     * Copyright (C) 2001 Niels Mller
     *  
     * 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.
     */
    
    #include "rsa-compat.h"
    
    #include "bignum.h"
    #include "md5.h"
    
    int
    R_SignInit(R_SIGNATURE_CTX *ctx,
               int digestAlgorithm)
    {
      if (digestAlgorithm != DA_MD5)
        return RE_DIGEST_ALGORITHM;
    
      md5_init(&ctx->hash);
    
      return 0;
    }
    
    int
    R_SignUpdate(R_SIGNATURE_CTX *ctx,
                 const uint8_t *data,
                 /* Length is an unsigned char according to rsaref.txt,
                  * but that must be a typo. */
                 unsigned length)
    {
      md5_update(&ctx->hash, length, data);
    
      return RE_SUCCESS;
    }
    
    int
    R_SignFinal(R_SIGNATURE_CTX *ctx,
                uint8_t *signature,
                unsigned *length,
                R_RSA_PRIVATE_KEY *key)
    {
      struct rsa_private_key k;
      int res;
      
      nettle_mpz_init_set_str_256(k.p,
                                  MAX_RSA_MODULUS_LEN, key->prime[0]);
      nettle_mpz_init_set_str_256(k.q,
                                  MAX_RSA_MODULUS_LEN, key->prime[1]);
      nettle_mpz_init_set_str_256(k.a,
                                  MAX_RSA_MODULUS_LEN, key->primeExponent[0]);
      nettle_mpz_init_set_str_256(k.b,
                                  MAX_RSA_MODULUS_LEN, key->primeExponent[1]);
      nettle_mpz_init_set_str_256(k.c,
                                  MAX_RSA_MODULUS_LEN, key->coefficient);
    
      if (rsa_prepare_private_key(&k) && (k.size <= MAX_RSA_MODULUS_LEN))
        {
          mpz_t s;
          mpz_init(s);
    
          rsa_md5_sign(&k, &ctx->hash, s);
          nettle_mpz_get_str_256(k.size, signature, s);
    
          mpz_clear(s);
    
          *length = k.size;
    
          res = RE_SUCCESS;
        }
      else
        res = RE_PRIVATE_KEY;
      
      mpz_clear(k.p);
      mpz_clear(k.q);
      mpz_clear(k.a);
      mpz_clear(k.b);
      mpz_clear(k.c);
    
      return res;
    }
    
    int
    R_VerifyInit(R_SIGNATURE_CTX *ctx,
                 int digestAlgorithm)
    {
      return R_SignInit(ctx, digestAlgorithm);
    }
    
    int
    R_VerifyUpdate(R_SIGNATURE_CTX *ctx,
                   const uint8_t *data,
                   /* Length is an unsigned char according to rsaref.txt,
                    * but that must be a typo. */
                   unsigned length)
    {
      return R_SignUpdate(ctx, data, length);
    }
    
    int
    R_VerifyFinal(R_SIGNATURE_CTX *ctx,
                  uint8_t *signature,
                  unsigned length,
                  R_RSA_PUBLIC_KEY *key)
    {
      struct rsa_public_key k;
      int res;
    
      nettle_mpz_init_set_str_256(k.n,
                                  MAX_RSA_MODULUS_LEN, key->modulus);
      nettle_mpz_init_set_str_256(k.e,
                                  MAX_RSA_MODULUS_LEN, key->exponent);
      
      if (rsa_prepare_public_key(&k) && (k.size == length))
        {
          mpz_t s;
      
          nettle_mpz_init_set_str_256(s,
    				  k.size, signature);
          res = rsa_md5_verify(&k, &ctx->hash, s)
    	? RE_SUCCESS : RE_SIGNATURE;
    
          mpz_clear(s);
        }
      else
        res = RE_PUBLIC_KEY;
    
      mpz_clear(k.n);
      mpz_clear(k.e);
    
      return res;
    }