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

« back to all changes in this revision

Viewing changes to ecc-scalar.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:
 
1
/* ecc-scalar.c */
 
2
 
 
3
/* nettle, low-level cryptographics library
 
4
 *
 
5
 * Copyright (C) 2013 Niels Möller
 
6
 *  
 
7
 * The nettle library is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU Lesser General Public License as published by
 
9
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 
10
 * option) any later version.
 
11
 * 
 
12
 * The nettle library is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
14
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
15
 * License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU Lesser General Public License
 
18
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
 
19
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
 * MA 02111-1301, USA.
 
21
 */
 
22
 
 
23
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
 
24
 
 
25
#if HAVE_CONFIG_H
 
26
# include "config.h"
 
27
#endif
 
28
 
 
29
#include "ecc.h"
 
30
#include "ecc-internal.h"
 
31
 
 
32
void
 
33
ecc_scalar_init (struct ecc_scalar *s, const struct ecc_curve *ecc)
 
34
{
 
35
  s->ecc = ecc;
 
36
  s->p = gmp_alloc_limbs (ecc->size);
 
37
}
 
38
 
 
39
void
 
40
ecc_scalar_clear (struct ecc_scalar *s)
 
41
{
 
42
  gmp_free_limbs (s->p, s->ecc->size);
 
43
}
 
44
 
 
45
int
 
46
ecc_scalar_set (struct ecc_scalar *s, const mpz_t z)
 
47
{
 
48
  mp_size_t size = s->ecc->size;
 
49
 
 
50
  if (mpz_sgn (z) <= 0 || mpz_limbs_cmp (z, s->ecc->q, size) >= 0)
 
51
    return 0;
 
52
 
 
53
  mpz_limbs_copy (s->p, z, size);
 
54
  return 1;
 
55
}
 
56
 
 
57
void
 
58
ecc_scalar_get (const struct ecc_scalar *s, mpz_t z)
 
59
{
 
60
  mpz_set_n (z, s->p, s->ecc->size);  
 
61
}