blob: d7a8e04bd037a0ccd70b910ce388f7ce2919de9e [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson7b79eb62013-09-12 18:48:29 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
Jeff Thompson7b79eb62013-09-12 18:48:29 -07004 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
Jeff Thompson7687dc02013-09-13 11:54:07 -07005 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson7b79eb62013-09-12 18:48:29 -07006 * See COPYING for copyright and distribution information.
7 */
8
Yingdi Yu31b4af22014-01-14 14:13:00 -08009#ifndef NDN_SEC_TPM_HPP
10#define NDN_SEC_TPM_HPP
Jeff Thompson7b79eb62013-09-12 18:48:29 -070011
12#include <string>
Yingdi Yu4f324632014-01-15 18:10:03 -080013#include "security-common.hpp"
14#include "../name.hpp"
15#include "../data.hpp"
16#include "public-key.hpp"
Jeff Thompson7b79eb62013-09-12 18:48:29 -070017
18namespace ndn {
19
Yingdi Yu31b4af22014-01-14 14:13:00 -080020class SecTpm {
Jeff Thompsona50703f2013-09-17 14:24:15 -070021public:
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080022 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
23
Jeff Thompson7b79eb62013-09-12 18:48:29 -070024 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070025 * The virtual destructor.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070026 */
27 virtual
Yingdi Yu31b4af22014-01-14 14:13:00 -080028 ~SecTpm() {}
Jeff Thompson7b79eb62013-09-12 18:48:29 -070029
Jeff Thompson7b79eb62013-09-12 18:48:29 -070030 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070031 * Generate a pair of asymmetric keys.
32 * @param keyName The name of the key pair.
33 * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA.
34 * @param keySize The size of the key pair.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070035 */
36 virtual void
Yingdi Yu31b4af22014-01-14 14:13:00 -080037 generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize) = 0;
Jeff Thompson7b79eb62013-09-12 18:48:29 -070038
39 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070040 * Get the public key
41 * @param keyName The name of public key.
42 * @return The public key.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070043 */
Jeff Thompson6c314bc2013-09-23 18:09:38 -070044 virtual ptr_lib::shared_ptr<PublicKey>
Yingdi Yu31b4af22014-01-14 14:13:00 -080045 getPublicKeyFromTpm(const Name& keyName) = 0;
Jeff Thompson7b79eb62013-09-12 18:48:29 -070046
47 /**
Jeff Thompson4c11b9f2013-09-13 11:05:28 -070048 * Fetch the private key for keyName and sign the data, returning a signature Blob.
49 * @param data Pointer to the input byte array.
50 * @param dataLength The length of data.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070051 * @param keyName The name of the signing key.
52 * @param digestAlgorithm the digest algorithm.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070053 * @return The signature, or a null pointer if signing fails.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070054 */
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080055 virtual Block
Yingdi Yu31b4af22014-01-14 14:13:00 -080056 sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm) = 0;
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080057
Alexander Afanasyev04b22a92014-01-05 22:40:17 -080058 virtual void
Yingdi Yu31b4af22014-01-14 14:13:00 -080059 sign(Data &data, const Name& keyName, DigestAlgorithm digestAlgorithm) = 0;
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080060
Jeff Thompson7b79eb62013-09-12 18:48:29 -070061 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070062 * Decrypt data.
63 * @param keyName The name of the decrypting key.
64 * @param data The byte to be decrypted.
65 * @param dataLength the length of data.
Jeff Thompsoned978ee2013-12-13 12:29:43 -080066 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric encryption is used.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070067 * @return The decrypted data.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070068 */
Alexander Afanasyev64a3d812014-01-05 23:35:05 -080069 virtual ConstBufferPtr
Yingdi Yu31b4af22014-01-14 14:13:00 -080070 decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070071
Jeff Thompson7b79eb62013-09-12 18:48:29 -070072 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070073 * Encrypt data.
74 * @param keyName The name of the encrypting key.
75 * @param data The byte to be encrypted.
76 * @param dataLength the length of data.
Jeff Thompsoned978ee2013-12-13 12:29:43 -080077 * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric encryption is used.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070078 * @return The encrypted data.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070079 */
Alexander Afanasyev64a3d812014-01-05 23:35:05 -080080 virtual ConstBufferPtr
Yingdi Yu31b4af22014-01-14 14:13:00 -080081 encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070082
Jeff Thompson7b79eb62013-09-12 18:48:29 -070083 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070084 * @brief Generate a symmetric key.
85 * @param keyName The name of the key.
86 * @param keyType The type of the key, e.g. KEY_TYPE_AES.
87 * @param keySize The size of the key.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070088 */
89 virtual void
Yingdi Yu31b4af22014-01-14 14:13:00 -080090 generateSymmetricKey(const Name& keyName, KeyType keyType, int keySize) = 0;
Jeff Thompson7b79eb62013-09-12 18:48:29 -070091
92 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070093 * Check if a particular key exists.
94 * @param keyName The name of the key.
95 * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC.
96 * @return True if the key exists, otherwise false.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070097 */
98 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070099 doesKeyExist(const Name& keyName, KeyClass keyClass) = 0;
Jeff Thompson7b79eb62013-09-12 18:48:29 -0700100};
101
102}
103
104#endif