aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/mpi/mpicoder.c88
1 files changed, 0 insertions, 88 deletions
diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c
index d7684aa7f65c..f26b41fcb48c 100644
--- a/lib/mpi/mpicoder.c
+++ b/lib/mpi/mpicoder.c
@@ -20,72 +20,8 @@
20 20
21#include "mpi-internal.h" 21#include "mpi-internal.h"
22 22
23#define DIM(v) (sizeof(v)/sizeof((v)[0]))
24#define MAX_EXTERN_MPI_BITS 16384 23#define MAX_EXTERN_MPI_BITS 16384
25 24
26static uint8_t asn[15] = /* Object ID is 1.3.14.3.2.26 */
27{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
28 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14
29};
30
31MPI do_encode_md(const void *sha_buffer, unsigned nbits)
32{
33 int nframe = (nbits + 7) / 8;
34 uint8_t *frame, *fr_pt;
35 int i = 0, n;
36 size_t asnlen = DIM(asn);
37 MPI a = NULL;
38
39 if (SHA1_DIGEST_LENGTH + asnlen + 4 > nframe)
40 pr_info("MPI: can't encode a %d bit MD into a %d bits frame\n",
41 (int)(SHA1_DIGEST_LENGTH * 8), (int)nbits);
42
43 /* We encode the MD in this way:
44 *
45 * 0 A PAD(n bytes) 0 ASN(asnlen bytes) MD(len bytes)
46 *
47 * PAD consists of FF bytes.
48 */
49 frame = kmalloc(nframe, GFP_KERNEL);
50 if (!frame)
51 return NULL;
52 n = 0;
53 frame[n++] = 0;
54 frame[n++] = 1; /* block type */
55 i = nframe - SHA1_DIGEST_LENGTH - asnlen - 3;
56
57 if (i <= 1) {
58 pr_info("MPI: message digest encoding failed\n");
59 kfree(frame);
60 return a;
61 }
62
63 memset(frame + n, 0xff, i);
64 n += i;
65 frame[n++] = 0;
66 memcpy(frame + n, &asn, asnlen);
67 n += asnlen;
68 memcpy(frame + n, sha_buffer, SHA1_DIGEST_LENGTH);
69 n += SHA1_DIGEST_LENGTH;
70
71 i = nframe;
72 fr_pt = frame;
73
74 if (n != nframe) {
75 printk
76 ("MPI: message digest encoding failed, frame length is wrong\n");
77 kfree(frame);
78 return a;
79 }
80
81 a = mpi_alloc((nframe + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB);
82 if (a)
83 mpi_set_buffer(a, frame, nframe, 0);
84 kfree(frame);
85
86 return a;
87}
88
89MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread) 25MPI mpi_read_from_buffer(const void *xbuffer, unsigned *ret_nread)
90{ 26{
91 const uint8_t *buffer = xbuffer; 27 const uint8_t *buffer = xbuffer;
@@ -213,30 +149,6 @@ int mpi_fromstr(MPI val, const char *str)
213EXPORT_SYMBOL_GPL(mpi_fromstr); 149EXPORT_SYMBOL_GPL(mpi_fromstr);
214 150
215/**************** 151/****************
216 * Special function to get the low 8 bytes from an mpi.
217 * This can be used as a keyid; KEYID is an 2 element array.
218 * Return the low 4 bytes.
219 */
220u32 mpi_get_keyid(const MPI a, u32 *keyid)
221{
222#if BYTES_PER_MPI_LIMB == 4
223 if (keyid) {
224 keyid[0] = a->nlimbs >= 2 ? a->d[1] : 0;
225 keyid[1] = a->nlimbs >= 1 ? a->d[0] : 0;
226 }
227 return a->nlimbs >= 1 ? a->d[0] : 0;
228#elif BYTES_PER_MPI_LIMB == 8
229 if (keyid) {
230 keyid[0] = a->nlimbs ? (u32) (a->d[0] >> 32) : 0;
231 keyid[1] = a->nlimbs ? (u32) (a->d[0] & 0xffffffff) : 0;
232 }
233 return a->nlimbs ? (u32) (a->d[0] & 0xffffffff) : 0;
234#else
235#error Make this function work with other LIMB sizes
236#endif
237}
238
239/****************
240 * Return an allocated buffer with the MPI (msb first). 152 * Return an allocated buffer with the MPI (msb first).
241 * NBYTES receives the length of this buffer. Caller must free the 153 * NBYTES receives the length of this buffer. Caller must free the
242 * return string (This function does return a 0 byte buffer with NBYTES 154 * return string (This function does return a 0 byte buffer with NBYTES