]>
git.ipfire.org Git - people/ms/strongswan.git/blob - linux/lib/libfreeswan/keyblobtoid.c
2 * generate printable key IDs
3 * Copyright (C) 2002 Henry Spencer.
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Library General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/lgpl.txt>.
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 * License for more details.
15 * RCSID $Id: keyblobtoid.c,v 1.1 2004/03/15 20:35:26 as Exp $
21 - keyblobtoid - generate a printable key ID from an RFC 2537/3110 key blob
22 * Current algorithm is just to use first nine base64 digits.
25 keyblobtoid(src
, srclen
, dst
, dstlen
)
26 const unsigned char *src
;
28 char *dst
; /* need not be valid if dstlen is 0 */
35 if (srclen
< (NDIG
*6 + 7)/8) {
36 strcpy(buf
, "?len= ?");
37 buf
[5] = '0' + srclen
;
40 (void) datatot(src
, srclen
, 64, buf
, NDIG
+1);
45 if (strlen(buf
)+1 > dstlen
)
46 *(buf
+ dstlen
- 1) = '\0';
53 - splitkeytoid - generate a printable key ID from exponent/modulus pair
54 * Just constructs the beginnings of a key blob and calls keyblobtoid().
57 splitkeytoid(e
, elen
, m
, mlen
, dst
, dstlen
)
58 const unsigned char *e
;
60 const unsigned char *m
;
62 char *dst
; /* need not be valid if dstlen is 0 */
65 unsigned char buf
[KEYID_BUF
]; /* ample room */
66 unsigned char *bufend
= buf
+ sizeof(buf
);
73 else if ((elen
&~ 0xffff) == 0) {
75 *p
++ = (elen
>>8) & 0xff;
78 return 0; /* unrepresentable exponent length */
94 return keyblobtoid(buf
, p
- buf
, dst
, dstlen
);
99 #ifdef KEYBLOBTOID_MAIN
110 typedef unsigned char uc
;
111 uc hexblob
[] = "\x01\x03\x85\xf2\xd6\x76\x9b\x03\x59\xb6\x21\x52";
113 uc hexm
[] = "\x85\xf2\xd6\x76\x9b\x03\x59\xb6\x21\x52\xef\x85";
114 char b64nine
[] = "AQOF8tZ2m";
115 char b64six
[] = "AQOF8t";
119 size_t bl
= strlen(b
) + 1;
122 n
= keyblobtoid(hexblob
, strlen(hexblob
), buf
, sizeof(buf
));
124 fprintf(stderr
, "%s: keyblobtoid returned %d not %d\n",
128 if (strcmp(buf
, b
) != 0) {
129 fprintf(stderr
, "%s: keyblobtoid generated `%s' not `%s'\n",
133 n
= splitkeytoid(hexe
, strlen(hexe
), hexm
, strlen(hexm
), buf
,
136 fprintf(stderr
, "%s: splitkeytoid returned %d not %d\n",
140 if (strcmp(buf
, b
) != 0) {
141 fprintf(stderr
, "%s: splitkeytoid generated `%s' not `%s'\n",
148 #endif /* KEYBLOBTOID_MAIN */