throw runtime_error("Key generation failed");
}
+std::string RSAContext::getPubKeyHash()
+{
+ unsigned char hash[20];
+ unsigned char N[mpi_size(&d_context.N)];
+ mpi_write_binary(&d_context.N, N, sizeof(N));
+ unsigned char E[mpi_size(&d_context.E)];
+ mpi_write_binary(&d_context.E, E, sizeof(E));
+
+ sha1_context ctx;
+ sha1_starts(&ctx);
+ sha1_update(&ctx, N, sizeof(N));
+ sha1_update(&ctx, E, sizeof(E));
+ sha1_finish(&ctx, hash);
+ return string((char*)hash, sizeof(hash));
+}
+
std::string RSAContext::convertToISC(unsigned int algorithm) const
{
string ret;
}
static pthread_mutex_t g_signatures_lock = PTHREAD_MUTEX_INITIALIZER;
-static map<pair<RSAContext, string>, string> g_signatures;
+static map<pair<string, string>, string> g_signatures;
void fillOutRRSIG(DNSSECPrivateKey& dpk, const std::string& signQName, RRSIGRecordContent& rrc, vector<shared_ptr<DNSRecordContent> >& toSign)
{
string realhash=getHashForRRSET(signQName, rrc, toSign); // this is what we sign
unsigned char signature[mpi_size(&rc.getContext().N)];
-
+ pair<string, string> lookup(rc.getPubKeyHash(), realhash);
+
{
Lock l(&g_signatures_lock);
-
- // this is mindbogglingly inefficient, we store the whole private key as index!
- if(g_signatures.count(make_pair(rc, realhash))) {
- rrc.d_signature=g_signatures[make_pair(rc, realhash)];
+ if(g_signatures.count(lookup)) {
+ // cerr<<"Hit!"<<endl;
+ rrc.d_signature=g_signatures[lookup];
return;
}
+ else
+ cerr<<"Miss!"<<endl;
}
int ret=rsa_pkcs1_sign(&rc.getContext(), RSA_PRIVATE,
rrc.d_signature.assign((char*)signature, sizeof(signature));
Lock l(&g_signatures_lock);
- g_signatures[make_pair(rc, realhash)] = rrc.d_signature;
+ g_signatures[lookup] = rrc.d_signature;
}