ec-private-key-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_EC_PRIVATE_KEY_LITE_HPP
23 #define NDN_EC_PRIVATE_KEY_LITE_HPP
24 
25 #include "../util/blob-lite.hpp"
26 #include "../../c/errors.h"
27 #include "../../c/security/ec-private-key-types.h"
28 
29 namespace ndn {
30 
36 public:
37  struct ec_key_st* debugGetPrivateKey() { return this->privateKey; }
38 
43 
48 
57  ndn_Error
58  decode(const uint8_t* privateKeyDer, size_t privateKeyDerLength);
59 
67  ndn_Error
68  decode(const BlobLite& privateKeyDer)
69  {
70  return decode(privateKeyDer.buf(), privateKeyDer.size());
71  }
72 
82  ndn_Error
83  setByCurve(int curveId, const uint8_t* value, size_t valueLength);
84 
93  ndn_Error
94  setByCurve(int curveId, const BlobLite& value)
95  {
96  return setByCurve(curveId, value.buf(), value.size());
97  }
98 
107  ndn_Error
108  generate(uint32_t keySize);
109 
123  ndn_Error
125  (bool includeParameters, uint8_t* encoding, size_t& encodingLength) const;
126 
140  ndn_Error
142  (bool includeParameters, uint8_t* encoding, size_t& encodingLength) const;
143 
155  ndn_Error
157  (const uint8_t* data, size_t dataLength, uint8_t* signature,
158  size_t& signatureLength) const;
159 
170  ndn_Error
172  (const BlobLite& data, uint8_t* signature, size_t& signatureLength) const
173  {
174  return signWithSha256(data.buf(), data.size(), signature, signatureLength);
175  }
176 
182  static EcPrivateKeyLite&
183  downCast(ndn_EcPrivateKey& blob) { return *(EcPrivateKeyLite*)&blob; }
184 
185  static const EcPrivateKeyLite&
186  downCast(const ndn_EcPrivateKey& blob) { return *(EcPrivateKeyLite*)&blob; }
187 
188 private:
189  // Don't allow copying since we don't reference count the allocated value.
190  EcPrivateKeyLite(const EcPrivateKeyLite& other);
191  EcPrivateKeyLite& operator=(const EcPrivateKeyLite& other);
192 };
193 
194 }
195 
196 #endif
A struct ndn_EcPrivateKey holds a decoded EC private key for use in crypto operations.
Definition: ec-private-key-types.h:34
size_t size() const
Return size given to the constructor.
Definition: blob-lite.hpp:61
static EcPrivateKeyLite & downCast(ndn_EcPrivateKey &blob)
Downcast the reference to the ndn_EcPrivateKey struct to a EcPrivateKeyLite.
Definition: ec-private-key-lite.hpp:183
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
EcPrivateKeyLite()
Create an EcPrivateKeyLite with a null value.
Definition: ec-private-key-lite.cpp:27
ndn_Error encodePrivateKey(bool includeParameters, uint8_t *encoding, size_t &encodingLength) const
Encode the DER-encoded private key.
Definition: ec-private-key-lite.cpp:59
ndn_Error decode(const BlobLite &privateKeyDer)
Decode the privateKeyDer and set this EcPrivateKeyLite, allocating memory as needed.
Definition: ec-private-key-lite.hpp:68
ndn_Error setByCurve(int curveId, const BlobLite &value)
Set the the private key from the given curveId, using the value to create a BIGNUM, allocating memory as needed.
Definition: ec-private-key-lite.hpp:94
~EcPrivateKeyLite()
Finalize the EcPrivateKeyLite, freeing memory if needed.
Definition: ec-private-key-lite.cpp:32
ndn_Error signWithSha256(const uint8_t *data, size_t dataLength, uint8_t *signature, size_t &signatureLength) const
Use this private key to sign the data using EcdsaWithSha256.
Definition: ec-private-key-lite.cpp:75
An EcPrivateKeyLite holds a decoded or generated EC private key for use in crypto operations...
Definition: ec-private-key-lite.hpp:35
ndn_Error generate(uint32_t keySize)
Generate a key pair and set this EcPrivateKeyLite, allocating memory as needed.
Definition: ec-private-key-lite.cpp:52
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
const uint8_t * buf() const
Return buf given to the constructor.
Definition: blob-lite.hpp:55
ndn_Error decode(const uint8_t *privateKeyDer, size_t privateKeyDerLength)
Decode the privateKeyDer and set this EcPrivateKeyLite, allocating memory as needed.
Definition: ec-private-key-lite.cpp:39
ndn_Error encodePublicKey(bool includeParameters, uint8_t *encoding, size_t &encodingLength) const
Encode the DER-encoded EC SubjectPublicKeyInfo.
Definition: ec-private-key-lite.cpp:67
ndn_Error setByCurve(int curveId, const uint8_t *value, size_t valueLength)
Set the the private key from the given curveId, using the value to create a BIGNUM, allocating memory as needed.
Definition: ec-private-key-lite.cpp:46