#ifndef _DH_KEYS_H_
#define _DH_KEYS_H_
#include <AppleCSPContext.h>
#include <AppleCSPSession.h>
#include "AppleCSPKeys.h"
#include <DH_csp.h>
#include <openssl/dh_legacy.h>
#include <security_cdsa_utilities/context.h>
#include <security_utilities/debugging.h>
#include <security_asn1/SecNssCoder.h>
#include <Security/osKeyTemplates.h>
#define DH_PUB_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS3
#define DH_PRIV_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS3
#define DH_MIN_KEY_SIZE 512
#define DH_MAX_KEY_SIZE 2048
#define cspDhDebug(args...) secinfo("dhDebug", ## args)
class DHBinaryKey : public BinaryKey {
public:
DHBinaryKey(DH *dhKey = NULL);
~DHBinaryKey();
void generateKeyBlob(
Allocator &allocator,
CssmData &blob,
CSSM_KEYBLOB_FORMAT &format,
AppleCSPSession &session,
const CssmKey *paramKey,
CSSM_KEYATTR_FLAGS &attrFlags);
DH *mDhKey;
};
class DHKeyPairGenContext :
public AppleCSPContext, private AppleKeyPairGenContext {
public:
DHKeyPairGenContext(
AppleCSPSession &session,
const Context &) :
AppleCSPContext(session),
mGenAttrs(NULL) {}
~DHKeyPairGenContext() { freeGenAttrs(); }
void init(
const Context &,
bool) { }
void generate(
const Context &context,
CssmKey &pubKey,
CssmKey &privKey);
void generate(
const Context &context,
BinaryKey &pubBinKey,
BinaryKey &privBinKey,
uint32 &keySize);
void generate(
const Context &context,
uint32 bitSize,
CssmData ¶ms,
uint32 &attrCount,
Context::Attr * &attrs);
bool changed(const Context &context) { return true; }
void dhGenParams(
uint32 keySizeInBits,
unsigned g, int privValueLength, NSS_DHParameter &algParams,
SecNssCoder &coder);
private:
Context::Attr *mGenAttrs;
void freeGenAttrs();
};
class DHKeyInfoProvider : public CSPKeyInfoProvider
{
private:
DHKeyInfoProvider(
const CssmKey &cssmKey,
AppleCSPSession &session);
public:
static CSPKeyInfoProvider *provider(
const CssmKey &cssmKey,
AppleCSPSession &session);
~DHKeyInfoProvider() { }
void CssmKeyToBinary(
CssmKey *paramKey, CSSM_KEYATTR_FLAGS &attrFlags, BinaryKey **binKey); void QueryKeySizeInBits(
CSSM_KEY_SIZE &keySize); bool getHashableBlob(
Allocator &allocator,
CssmData &hashBlob);
};
#endif