1 //********************************************************************************** 2 //LibEncryptMsg Copyright 2018 Evgeny Pokhilko 3 //<https://evpo.net/libencryptmsg> 4 // 5 //LibEncryptMsg is released under the Simplified BSD License (see license.txt) 6 //********************************************************************************** 7 #include "algo_spec.h" 8 9 namespace EncryptMsg 10 { GetAlgoSpec(CipherAlgo cipher_algo)11 const AlgoSpec &GetAlgoSpec(CipherAlgo cipher_algo) 12 { 13 switch(cipher_algo) 14 { 15 case CipherAlgo::TripleDES: 16 static AlgoSpec triple_des = 17 { 18 CipherAlgo::TripleDES, 19 "3DES/CFB", 20 8, 21 192 22 }; 23 return triple_des; 24 25 case CipherAlgo::CAST5: 26 27 static AlgoSpec cast5 = 28 { 29 CipherAlgo::CAST5, 30 "CAST5/CFB", 31 8, 32 128 33 }; 34 return cast5; 35 36 case CipherAlgo::AES128: 37 38 static AlgoSpec aes128 = 39 { 40 CipherAlgo::AES128, 41 "AES-128/CFB", 42 16, 43 128 44 }; 45 return aes128; 46 47 case CipherAlgo::AES192: 48 49 static AlgoSpec aes192 = 50 { 51 CipherAlgo::AES192, 52 "AES-192/CFB", 53 16, 54 192 55 }; 56 return aes192; 57 58 case CipherAlgo::AES256: 59 60 static AlgoSpec aes256 = 61 { 62 CipherAlgo::AES256, 63 "AES-256/CFB", 64 16, 65 256 66 }; 67 return aes256; 68 69 case CipherAlgo::Camellia128: 70 71 static AlgoSpec camellia128 = 72 { 73 CipherAlgo::Camellia128, 74 "Camellia-128/CFB", 75 16, 76 128 77 }; 78 return camellia128; 79 80 case CipherAlgo::Camellia192: 81 82 static AlgoSpec camellia192 = 83 { 84 CipherAlgo::Camellia192, 85 "Camellia-192/CFB", 86 16, 87 192 88 }; 89 return camellia192; 90 91 case CipherAlgo::Camellia256: 92 93 static AlgoSpec camellia256 = 94 { 95 CipherAlgo::Camellia256, 96 "Camellia-256/CFB", 97 16, 98 256 99 }; 100 return camellia256; 101 102 case CipherAlgo::Twofish: 103 104 static AlgoSpec twofish = 105 { 106 CipherAlgo::Twofish, 107 "Twofish/CFB", 108 16, 109 256 110 }; 111 return twofish; 112 113 default: 114 static AlgoSpec unknown = 115 { 116 CipherAlgo::Unknown, 117 "", 118 0, 119 0 120 }; 121 return unknown; 122 } 123 } 124 GetHashSpec(HashAlgo hash_algo)125 const HashSpec &GetHashSpec(HashAlgo hash_algo) 126 { 127 switch(hash_algo) 128 { 129 case HashAlgo::SHA160: 130 static HashSpec sha160 = 131 { 132 HashAlgo::SHA160, 133 "OpenPGP-S2K(SHA-160)" 134 }; 135 return sha160; 136 case HashAlgo::SHA256: 137 static HashSpec sha256 = 138 { 139 HashAlgo::SHA256, 140 "OpenPGP-S2K(SHA-256)" 141 }; 142 return sha256; 143 case HashAlgo::SHA384: 144 static HashSpec sha384 = 145 { 146 HashAlgo::SHA384, 147 "OpenPGP-S2K(SHA-384)" 148 }; 149 return sha384; 150 case HashAlgo::SHA512: 151 static HashSpec sha512 = 152 { 153 HashAlgo::SHA512, 154 "OpenPGP-S2K(SHA-512)" 155 }; 156 return sha512; 157 case HashAlgo::SHA224: 158 static HashSpec sha224 = 159 { 160 HashAlgo::SHA224, 161 "OpenPGP-S2K(SHA-224)" 162 }; 163 return sha224; 164 default: 165 static HashSpec unknown = 166 { 167 HashAlgo::Unknown, 168 "" 169 }; 170 return unknown; 171 } 172 } 173 GetCompressionSpec(Compression compression)174 const CompressionSpec &GetCompressionSpec(Compression compression) 175 { 176 switch(compression) 177 { 178 case Compression::ZIP: 179 static CompressionSpec zip = 180 { 181 Compression::ZIP, 182 "deflate" 183 }; 184 return zip; 185 case Compression::ZLIB: 186 static CompressionSpec zlib = 187 { 188 Compression::ZLIB, 189 "zlib" 190 }; 191 return zlib; 192 case Compression::BZip2: 193 static CompressionSpec bzip2 = 194 { 195 Compression::BZip2, 196 "bz2" 197 }; 198 return bzip2; 199 default: 200 static CompressionSpec unknown = 201 { 202 Compression::Unknown, 203 "" 204 }; 205 return unknown; 206 } 207 } 208 } 209 210