~ubuntu-branches/ubuntu/vivid/nettle/vivid-proposed

« back to all changes in this revision

Viewing changes to pkcs1-rsa-sha256.c

  • Committer: Package Import Robot
  • Author(s): Magnus Holmgren
  • Date: 2013-05-04 19:50:28 UTC
  • mfrom: (1.4.6) (3.1.11 experimental)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20130504195028-fp6c9fw1tsm5scwa
Tags: 2.7-1
* New upstream release (Closes: #706081).
* Include watch file improvements from Bart Martens <bartm@debian.org>
  via the QA system.

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 Niels M�ller
 
8
 * Copyright (C) 2001, 2003, 2006 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_sha256_encode(mpz_t m, unsigned size, struct sha256_ctx *hash)
 
63
pkcs1_rsa_sha256_encode(mpz_t m, unsigned key_size, struct sha256_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(sha256_prefix),
70
 
                             sha256_prefix,
71
 
                             SHA256_DIGEST_SIZE))
 
69
  p = _pkcs1_signature_prefix(key_size, em,
 
70
                              sizeof(sha256_prefix),
 
71
                              sha256_prefix,
 
72
                              SHA256_DIGEST_SIZE);
 
73
  if (p)
72
74
    {
73
 
      sha256_digest(hash, SHA256_DIGEST_SIZE, em + size - SHA256_DIGEST_SIZE);
74
 
      nettle_mpz_set_str_256_u(m, size, em);
 
75
      sha256_digest(hash, SHA256_DIGEST_SIZE, p);
 
76
      nettle_mpz_set_str_256_u(m, key_size, em);
75
77
      return 1;
76
78
    }
77
79
  else
79
81
}
80
82
 
81
83
int
82
 
pkcs1_rsa_sha256_encode_digest(mpz_t m, unsigned size, const uint8_t *digest)
 
84
pkcs1_rsa_sha256_encode_digest(mpz_t m, unsigned key_size, const uint8_t *digest)
83
85
{
84
 
  TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_BITS / 8);
85
 
  TMP_ALLOC(em, size);
 
86
  uint8_t *p;
 
87
  TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_SIZE);
 
88
  TMP_ALLOC(em, key_size);
86
89
 
87
 
  if (pkcs1_signature_prefix(size, em,
88
 
                             sizeof(sha256_prefix),
89
 
                             sha256_prefix,
90
 
                             SHA256_DIGEST_SIZE))
 
90
  p = _pkcs1_signature_prefix(key_size, em,
 
91
                              sizeof(sha256_prefix),
 
92
                              sha256_prefix,
 
93
                              SHA256_DIGEST_SIZE);
 
94
  if (p)
91
95
    {
92
 
      memcpy(em + size - SHA256_DIGEST_SIZE, digest, SHA256_DIGEST_SIZE);
93
 
      nettle_mpz_set_str_256_u(m, size, em);
 
96
      memcpy(p, digest, SHA256_DIGEST_SIZE);
 
97
      nettle_mpz_set_str_256_u(m, key_size, em);
94
98
      return 1;
95
99
    }
96
100
  else