Mercurial > dropbear
comparison libtommath/bn_mp_read_unsigned_bin.c @ 1655:f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
* make key-generation compliant to FIPS 186.4
* fix includes in tommath_class.h
* update fuzzcorpus instead of error-out
* fixup fuzzing make-targets
* update Makefile.in
* apply necessary patches to ltm sources
* clean-up not required ltm files
* update to vanilla ltm 1.1.0
this already only contains the required files
* remove set/get double
author | Steffen Jaeckel <s_jaeckel@gmx.de> |
---|---|
date | Mon, 16 Sep 2019 15:50:38 +0200 |
parents | 8bba51a55704 |
children |
comparison
equal
deleted
inserted
replaced
1654:cc0fc5131c5c | 1655:f52919ffd3b1 |
---|---|
1 #include <tommath_private.h> | 1 #include "tommath_private.h" |
2 #ifdef BN_MP_READ_UNSIGNED_BIN_C | 2 #ifdef BN_MP_READ_UNSIGNED_BIN_C |
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis | 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis |
4 * | 4 * |
5 * LibTomMath is a library that provides multiple-precision | 5 * LibTomMath is a library that provides multiple-precision |
6 * integer arithmetic as well as number theoretic functionality. | 6 * integer arithmetic as well as number theoretic functionality. |
7 * | 7 * |
8 * The library was designed directly after the MPI library by | 8 * The library was designed directly after the MPI library by |
9 * Michael Fromberger but has been written from scratch with | 9 * Michael Fromberger but has been written from scratch with |
10 * additional optimizations in place. | 10 * additional optimizations in place. |
11 * | 11 * |
12 * The library is free for all purposes without any express | 12 * SPDX-License-Identifier: Unlicense |
13 * guarantee it works. | |
14 * | |
15 * Tom St Denis, [email protected], http://libtom.org | |
16 */ | 13 */ |
17 | 14 |
18 /* reads a unsigned char array, assumes the msb is stored first [big endian] */ | 15 /* reads a unsigned char array, assumes the msb is stored first [big endian] */ |
19 int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c) | 16 int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c) |
20 { | 17 { |
21 int res; | 18 int res; |
22 | 19 |
23 /* make sure there are at least two digits */ | 20 /* make sure there are at least two digits */ |
24 if (a->alloc < 2) { | 21 if (a->alloc < 2) { |
25 if ((res = mp_grow(a, 2)) != MP_OKAY) { | 22 if ((res = mp_grow(a, 2)) != MP_OKAY) { |
26 return res; | 23 return res; |
27 } | 24 } |
28 } | 25 } |
29 | 26 |
30 /* zero the int */ | 27 /* zero the int */ |
31 mp_zero (a); | 28 mp_zero(a); |
32 | 29 |
33 /* read the bytes in */ | 30 /* read the bytes in */ |
34 while (c-- > 0) { | 31 while (c-- > 0) { |
35 if ((res = mp_mul_2d (a, 8, a)) != MP_OKAY) { | 32 if ((res = mp_mul_2d(a, 8, a)) != MP_OKAY) { |
36 return res; | 33 return res; |
37 } | 34 } |
38 | 35 |
39 #ifndef MP_8BIT | 36 #ifndef MP_8BIT |
40 a->dp[0] |= *b++; | 37 a->dp[0] |= *b++; |
41 a->used += 1; | 38 a->used += 1; |
42 #else | 39 #else |
43 a->dp[0] = (*b & MP_MASK); | 40 a->dp[0] = (*b & MP_MASK); |
44 a->dp[1] |= ((*b++ >> 7U) & 1); | 41 a->dp[1] |= ((*b++ >> 7) & 1u); |
45 a->used += 2; | 42 a->used += 2; |
46 #endif | 43 #endif |
47 } | 44 } |
48 mp_clamp (a); | 45 mp_clamp(a); |
49 return MP_OKAY; | 46 return MP_OKAY; |
50 } | 47 } |
51 #endif | 48 #endif |
52 | 49 |
53 /* ref: $Format:%D$ */ | 50 /* ref: HEAD -> master, tag: v1.1.0 */ |
54 /* git commit: $Format:%H$ */ | 51 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ |
55 /* commit time: $Format:%ai$ */ | 52 /* commit time: 2019-01-28 20:32:32 +0100 */ |