]>
Commit | Line | Data |
---|---|---|
d1b3e860 MW |
1 | /* |
2 | * Copyright (C) 2009 Martin Willi | |
3 | * Hochschule fuer Technik Rapperswil | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2 of the License, or (at your | |
8 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
9 | * | |
10 | * This program 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 General Public License | |
13 | * for more details. | |
14 | */ | |
15 | ||
16 | #include "pgp_encoder.h" | |
17 | ||
18 | #include <debug.h> | |
19 | ||
20 | /** | |
21 | * Build a PGPv3 fingerprint | |
22 | */ | |
23 | static bool build_v3_fingerprint(chunk_t *encoding, va_list args) | |
24 | { | |
25 | hasher_t *hasher; | |
26 | chunk_t n, e; | |
7daf5226 | 27 | |
da9724e6 MW |
28 | if (cred_encoding_args(args, CRED_PART_RSA_MODULUS, &n, |
29 | CRED_PART_RSA_PUB_EXP, &e, CRED_PART_END)) | |
d1b3e860 MW |
30 | { |
31 | hasher = lib->crypto->create_hasher(lib->crypto, HASH_MD5); | |
32 | if (!hasher) | |
33 | { | |
8b0e0910 TB |
34 | DBG1(DBG_LIB, "MD5 hash algorithm not supported, PGP" |
35 | " fingerprinting failed"); | |
d1b3e860 MW |
36 | return FALSE; |
37 | } | |
38 | /* remove leading zero bytes before hashing modulus and exponent */ | |
39 | while (n.len > 0 && n.ptr[0] == 0x00) | |
40 | { | |
41 | n = chunk_skip(n, 1); | |
42 | } | |
43 | while (e.len > 0 && e.ptr[0] == 0x00) | |
44 | { | |
45 | e = chunk_skip(e, 1); | |
46 | } | |
87dd205b MW |
47 | if (!hasher->allocate_hash(hasher, n, NULL) || |
48 | !hasher->allocate_hash(hasher, e, encoding)) | |
49 | { | |
50 | hasher->destroy(hasher); | |
51 | return FALSE; | |
52 | } | |
d1b3e860 MW |
53 | hasher->destroy(hasher); |
54 | return TRUE; | |
55 | } | |
56 | return FALSE; | |
57 | } | |
58 | ||
59 | /** | |
60 | * See header. | |
61 | */ | |
da9724e6 MW |
62 | bool pgp_encoder_encode(cred_encoding_type_t type, chunk_t *encoding, |
63 | va_list args) | |
d1b3e860 MW |
64 | { |
65 | switch (type) | |
66 | { | |
da9724e6 | 67 | case KEYID_PGPV3: |
d1b3e860 MW |
68 | return build_v3_fingerprint(encoding, args); |
69 | default: | |
70 | return FALSE; | |
71 | } | |
72 | } | |
73 |