~ubuntu-branches/ubuntu/utopic/nettle/utopic

« back to all changes in this revision

Viewing changes to pkcs1-rsa-sha512.c

  • Committer: Package Import Robot
  • Author(s): Magnus Holmgren
  • Date: 2013-05-07 22:57:14 UTC
  • mfrom: (8.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130507225714-s331yr8ov53dtt17
Tags: 2.7-2
Tag some (ECC related) symbols that only exist on some architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
/* nettle, low-level cryptographics library
7
7
 *
8
 
 * Copyright (C) 2001, 2003, 2006, 2010 Niels M�ller
 
8
 * Copyright (C) 2001, 2003, 2006, 2010 Niels Möller
9
9
 *  
10
10
 * The nettle library is free software; you can redistribute it and/or modify
11
11
 * it under the terms of the GNU Lesser General Public License as published by
19
19
 * 
20
20
 * You should have received a copy of the GNU Lesser General Public License
21
21
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
22
 
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23
 
 * MA 02111-1307, USA.
 
22
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
23
 * MA 02111-1301, USA.
24
24
 */
25
25
 
26
26
#if HAVE_CONFIG_H
60
60
};
61
61
 
62
62
int
63
 
pkcs1_rsa_sha512_encode(mpz_t m, unsigned size, struct sha512_ctx *hash)
 
63
pkcs1_rsa_sha512_encode(mpz_t m, unsigned key_size, struct sha512_ctx *hash)
64
64
{
65
 
  TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_BITS / 8);
66
 
  TMP_ALLOC(em, size);
 
65
  uint8_t *p;
 
66
  TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_SIZE);
 
67
  TMP_ALLOC(em, key_size);
67
68
 
68
 
  if (pkcs1_signature_prefix(size, em,
69
 
                             sizeof(sha512_prefix),
70
 
                             sha512_prefix,
71
 
                             SHA512_DIGEST_SIZE))
 
69
  p = _pkcs1_signature_prefix(key_size, em,
 
70
                              sizeof(sha512_prefix),
 
71
                              sha512_prefix,
 
72
                              SHA512_DIGEST_SIZE);
 
73
  if (p)
72
74
    {
73
 
      sha512_digest(hash, SHA512_DIGEST_SIZE,
74
 
                    em + size - SHA512_DIGEST_SIZE);
75
 
      nettle_mpz_set_str_256_u(m, size, em);
 
75
      sha512_digest(hash, SHA512_DIGEST_SIZE, p);
 
76
      nettle_mpz_set_str_256_u(m, key_size, em);
76
77
      return 1;
77
78
    }
78
79
  else
80
81
}
81
82
 
82
83
int
83
 
pkcs1_rsa_sha512_encode_digest(mpz_t m, unsigned size, const uint8_t *digest)
 
84
pkcs1_rsa_sha512_encode_digest(mpz_t m, unsigned key_size, const uint8_t *digest)
84
85
{
85
 
  TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_BITS / 8);
86
 
  TMP_ALLOC(em, size);
 
86
  uint8_t *p;
 
87
  TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_SIZE);
 
88
  TMP_ALLOC(em, key_size);
87
89
 
88
 
  if (pkcs1_signature_prefix(size, em,
89
 
                             sizeof(sha512_prefix),
90
 
                             sha512_prefix,
91
 
                             SHA512_DIGEST_SIZE))
 
90
  p = _pkcs1_signature_prefix(key_size, em,
 
91
                              sizeof(sha512_prefix),
 
92
                              sha512_prefix,
 
93
                              SHA512_DIGEST_SIZE);
 
94
  if (p)
92
95
    {
93
 
      memcpy(em + size - SHA512_DIGEST_SIZE, digest, SHA512_DIGEST_SIZE);
94
 
      nettle_mpz_set_str_256_u(m, size, em);
 
96
      memcpy(p, digest, SHA512_DIGEST_SIZE);
 
97
      nettle_mpz_set_str_256_u(m, key_size, em);
95
98
      return 1;
96
99
    }
97
100
  else