moved PGP types to pgp/pgp.h
[strongswan.git] / src / libstrongswan / pgp / pgp.c
1 /*
2 * Copyright (C) 2002-2009 Andreas Steffen
3 *
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "pgp.h"
18
19 ENUM_BEGIN(pgp_packet_tag_names, PGP_PKT_RESERVED, PGP_PKT_PUBLIC_SUBKEY,
20 "Reserved",
21 "Public-Key Encrypted Session Key Packet",
22 "Signature Packet",
23 "Symmetric-Key Encrypted Session Key Packet",
24 "One-Pass Signature Packet",
25 "Secret Key Packet",
26 "Public Key Packet",
27 "Secret Subkey Packet",
28 "Compressed Data Packet",
29 "Symmetrically Encrypted Data Packet",
30 "Marker Packet",
31 "Literal Data Packet",
32 "Trust Packet",
33 "User ID Packet",
34 "Public Subkey Packet"
35 );
36 ENUM_NEXT(pgp_packet_tag_names, PGP_PKT_USER_ATTRIBUTE, PGP_PKT_MOD_DETECT_CODE, PGP_PKT_PUBLIC_SUBKEY,
37 "User Attribute Packet",
38 "Sym. Encrypted and Integrity Protected Data Packet",
39 "Modification Detection Code Packet"
40 );
41 ENUM_END(pgp_packet_tag_names, PGP_PKT_MOD_DETECT_CODE);
42
43
44 ENUM_BEGIN(pgp_pubkey_alg_names, PGP_PUBKEY_ALG_RSA, PGP_PUBKEY_ALG_RSA_SIGN_ONLY,
45 "RSA",
46 "RSA_ENC_ONLY",
47 "RSA_SIGN_ONLY"
48 );
49 ENUM_NEXT(pgp_pubkey_alg_names, PGP_PUBKEY_ALG_ELGAMAL_ENC_ONLY, PGP_PUBKEY_ALG_DIFFIE_HELLMAN, PGP_PUBKEY_ALG_RSA_SIGN_ONLY,
50 "ELGAMAL_ENC_ONLY",
51 "DSA",
52 "ECC",
53 "ECDSA",
54 "ELGAMAL",
55 "DIFFIE_HELLMAN"
56 );
57 ENUM_END(pgp_pubkey_alg_names, PGP_PUBKEY_ALG_DIFFIE_HELLMAN);
58
59
60 ENUM(pgp_sym_alg_names, PGP_SYM_ALG_PLAIN, PGP_SYM_ALG_TWOFISH,
61 "PLAINTEXT",
62 "IDEA",
63 "3DES",
64 "CAST5",
65 "BLOWFISH",
66 "SAFER",
67 "DES",
68 "AES_128",
69 "AES_192",
70 "AES_256",
71 "TWOFISH"
72 );
73
74 /*
75 * Defined in header.
76 */
77 size_t pgp_length(chunk_t *blob, size_t len)
78 {
79 size_t size = 0;
80
81 if (len > blob->len)
82 {
83 return PGP_INVALID_LENGTH;
84 }
85 blob->len -= len;
86
87 while (len-- > 0)
88 {
89 size = 256*size + *blob->ptr++;
90 }
91 return size;
92 }
93