Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame^] | 2 | * Copyright (C) 2013 Regents of the University of California. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 3 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame^] | 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_PRIVATE_KEY_STORAGE_HPP |
| 9 | #define NDN_PRIVATE_KEY_STORAGE_HPP |
| 10 | |
| 11 | #include <string> |
| 12 | #include "../../util/blob.hpp" |
| 13 | #include "../security-common.hpp" |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | class PrivateKeyStorage { |
| 18 | /** |
| 19 | * The virtual destructor |
| 20 | */ |
| 21 | virtual |
| 22 | ~PrivateKeyStorage(); |
| 23 | |
| 24 | #if 0 |
| 25 | /** |
| 26 | * @brief generate a pair of asymmetric keys |
| 27 | * @param keyName the name of the key pair |
| 28 | * @param keyType the type of the key pair, e.g. RSA |
| 29 | * @param keySize the size of the key pair |
| 30 | */ |
| 31 | virtual void |
| 32 | generateKeyPair(const string & keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048) = 0; |
| 33 | |
| 34 | /** |
| 35 | * @brief get the public key |
| 36 | * @param keyName the name of public key |
| 37 | * @return the public key |
| 38 | */ |
| 39 | virtual Ptr<Publickey> |
| 40 | getPublickey(const string & keyName) = 0; |
| 41 | #endif |
| 42 | |
| 43 | /** |
Jeff Thompson | 4c11b9f | 2013-09-13 11:05:28 -0700 | [diff] [blame] | 44 | * Fetch the private key for keyName and sign the data, returning a signature Blob. |
| 45 | * @param data Pointer to the input byte array. |
| 46 | * @param dataLength The length of data. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 47 | * @param keyName The name of the signing key. |
| 48 | * @param digestAlgorithm the digest algorithm. |
| 49 | * @return The signature, or 0 if signing fails. |
| 50 | */ |
| 51 | virtual Blob |
Jeff Thompson | 4c11b9f | 2013-09-13 11:05:28 -0700 | [diff] [blame] | 52 | sign(const unsigned char *data, unsigned int dataLength, const std::string& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256); |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 53 | |
| 54 | #if 0 |
| 55 | /** |
| 56 | * @brief decrypt data |
| 57 | * @param keyName the name of the decrypting key |
| 58 | * @param blob the blob to be decrypted |
| 59 | * @param sym if true symmetric encryption is used, otherwise asymmetric decryption is used. |
| 60 | * @return decrypted data |
| 61 | */ |
| 62 | virtual Ptr<Blob> |
| 63 | decrypt(const string & keyName, const Blob & data, bool sym = false) = 0; |
| 64 | |
| 65 | /** |
| 66 | * @brief encrypt data |
| 67 | * @param keyName the name of the encrypting key |
| 68 | * @param blob the blob to be encrypted |
| 69 | * @param sym if true symmetric encryption is used, otherwise asymmetric decryption is used. |
| 70 | * @return encrypted data |
| 71 | */ |
| 72 | virtual Ptr<Blob> |
| 73 | encrypt(const string & keyName, const Blob & pData, bool sym = false) = 0; |
| 74 | |
| 75 | /** |
| 76 | * @brief generate a symmetric key |
| 77 | * @param keyName the name of the key |
| 78 | * @param keyType the type of the key, e.g. AES |
| 79 | * @param keySize the size of the key |
| 80 | */ |
| 81 | virtual void |
| 82 | generateKey(const string & keyName, KeyType keyType = KEY_TYPE_AES, int keySize = 256) = 0; |
| 83 | |
| 84 | /** |
| 85 | * @brief check if a particular key exist |
| 86 | * @param keyName the name of the key |
| 87 | * @param keyClass the class of the key, e.g. public, private, or symmetric |
| 88 | * @return true if the key exists, otherwise false |
| 89 | */ |
| 90 | virtual bool |
| 91 | doesKeyExist(const string & keyName, KeyClass keyClass) = 0; |
| 92 | #endif |
| 93 | }; |
| 94 | |
| 95 | } |
| 96 | |
| 97 | #endif |