github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/src/support_libraries/tao_support/agile_crypto_support.h (about) 1 // Copyright (c) 2014, Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 14 #ifndef __AGILE_CRYPTO_SUPPORT_H__ 15 #define __AGILE_CRYPTO_SUPPORT_H__ 16 17 #include <stdio.h> 18 19 #include <sys/types.h> 20 #include <sys/stat.h> 21 #include <fcntl.h> 22 #include <unistd.h> 23 #include <string> 24 #include <list> 25 26 #include "taosupport.pb.h" 27 #include "keys.pb.h" 28 29 #include <openssl/rsa.h> 30 #include <openssl/x509.h> 31 #include <openssl/x509v3.h> 32 33 #ifndef byte 34 typedef unsigned char byte; 35 #endif 36 37 using std::string; 38 39 extern string Basic128BitCipherSuite; 40 extern string Basic192BitCipherSuite; 41 extern string Basic256BitCipherSuite; 42 43 class Signer { 44 public: 45 tao::CryptoHeader* ch_; 46 EVP_PKEY* sk_; 47 48 bool Sign(string& in, string* out); 49 bool Verify(string& msg, string& sig); 50 }; 51 52 class Verifier { 53 public: 54 tao::CryptoHeader* ch_; 55 EVP_PKEY* vk_; 56 57 bool Verify(string& msg, string& serialized_sig); 58 }; 59 60 class Crypter { 61 public: 62 tao::CryptoHeader* ch_; 63 string* encryptingKeyBytes_; 64 string* hmacKeyBytes_; 65 66 bool Encrypt(string& in, string* iv, string* mac, string* out); 67 bool Decrypt(string& in, string& iv, string& mac, string* out); 68 }; 69 70 class Deriver { 71 public: 72 tao::CryptoHeader* ch_; 73 string* secret_bytes_; 74 75 bool Derive(string& salt, string& context, string& in, string* out); 76 }; 77 78 bool CrypterAlgorithmNameFromCipherSuite(string& cipher_suite, string* crypter_name); 79 bool SignerAlgorithmNameFromCipherSuite(string& cipher_suite, string* signer_name); 80 81 Verifier* CryptoKeyToVerifier(tao::CryptoKey& ck); 82 Signer* CryptoKeyToSigner(tao::CryptoKey& ck); 83 Crypter* CryptoKeyToCrypter(tao::CryptoKey& ck); 84 Verifier* VerifierFromSigner(Signer* s); 85 Verifier* VerifierFromCertificate(string& der); 86 bool GenerateCryptoKey(string& type, tao::CryptoKey* ck); 87 tao::CryptoKey* SignerToCryptoKey(Signer* s); 88 tao::CryptoKey* VerifierToCryptoKey(Verifier* v); 89 tao::CryptoKey* CrypterToCryptoKey(Crypter* c); 90 bool SerializeECCKeyComponents(EC_KEY* ec_key, string* component); 91 bool DeserializeECCKeyComponents(string component, EC_KEY* ec_key); 92 93 bool Protect(Crypter& crypter, string& in, string* out); 94 bool Unprotect(Crypter& crypter, string& in, string* out); 95 bool KeyPrincipalBytes(Verifier* v, string* out); 96 bool UniversalKeyName(Verifier* v, string* out); 97 98 void PrintBytes(int size, byte* buf); 99 bool ReadFile(string& file_name, string* out); 100 bool WriteFile(string& file_name, string& in); 101 void PrintCryptoHeader(const tao::CryptoHeader& ch); 102 void PrintCryptoKey(const tao::CryptoKey& ck); 103 #endif 104 105