crypto-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_CRYPTOLITE_HPP
23 #define NDN_CRYPTOLITE_HPP
24 
25 #include "blob-lite.hpp"
26 #include "../../c/errors.h"
27 
28 namespace ndn {
29 
33 class CryptoLite {
34 public:
42  static void
43  digestSha256(const uint8_t* data, size_t dataLength, uint8_t *digest);
44 
51  static void
52  digestSha256(const BlobLite& data, uint8_t *digest)
53  {
54  digestSha256(data.buf(), data.size(), digest);
55  }
56 
64  static ndn_Error
65  generateRandomBytes(uint8_t* buffer, size_t bufferLength);
66 
77  static void
79  (const uint8_t* key, size_t keyLength, const uint8_t* data, size_t dataLength,
80  uint8_t *digest);
81 
90  static void
92  (const BlobLite& key, const BlobLite& data, uint8_t *digest)
93  {
94  computeHmacWithSha256(key.buf(), key.size(), data.buf(), data.size(), digest);
95  }
96 
105  static bool
107  (const uint8_t* signature, size_t signatureLength, const uint8_t *data,
108  size_t dataLength);
109 
116  static bool
117  verifyDigestSha256Signature(const BlobLite& signature, const BlobLite& data)
118  {
120  (signature.buf(), signature.size(), data.buf(), data.size());
121  }
122 };
123 
124 }
125 
126 #endif
size_t size() const
Return size given to the constructor.
Definition: blob-lite.hpp:61
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
CryptoLite has static methods for basic cryptography operations.
Definition: crypto-lite.hpp:33
static void digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
Compute the sha-256 digest of data.
Definition: crypto-lite.cpp:28
static bool verifyDigestSha256Signature(const uint8_t *signature, size_t signatureLength, const uint8_t *data, size_t dataLength)
Verify that the DigestSha256 of the data equals the signature.
Definition: crypto-lite.cpp:49
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
static bool verifyDigestSha256Signature(const BlobLite &signature, const BlobLite &data)
Verify that the DigestSha256 of the data equals the signature.
Definition: crypto-lite.hpp:117
const uint8_t * buf() const
Return buf given to the constructor.
Definition: blob-lite.hpp:55
static void digestSha256(const BlobLite &data, uint8_t *digest)
Compute the sha-256 digest of data.
Definition: crypto-lite.hpp:52
static ndn_Error generateRandomBytes(uint8_t *buffer, size_t bufferLength)
Fill the buffer with random bytes.
Definition: crypto-lite.cpp:34
static void computeHmacWithSha256(const uint8_t *key, size_t keyLength, const uint8_t *data, size_t dataLength, uint8_t *digest)
Compute the HMAC with sha-256 of data, as defined in http://tools.ietf.org/html/rfc2104#section-2 ...
Definition: crypto-lite.cpp:41