chiark
/
gitweb
/
~ianmdlvl
/
secnet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
privcache: New closure for signature key handling
[secnet.git]
/
rsa.c
diff --git
a/rsa.c
b/rsa.c
index 83f6e7d99a345774de5df43ff16e912f33bb3d2e..1c37ef98acf3abec9e641267d532e720efa74f27 100644
(file)
--- a/
rsa.c
+++ b/
rsa.c
@@
-42,7
+42,6
@@
#define mpp(s,n) do { char *p = mpz_get_str(NULL,16,n); printf("%s 0x%sL\n", s, p); free(p); } while (0)
struct rsacommon {
#define mpp(s,n) do { char *p = mpz_get_str(NULL,16,n); printf("%s 0x%sL\n", s, p); free(p); } while (0)
struct rsacommon {
- struct hash_if *hashi;
uint8_t *hashbuf;
};
uint8_t *hashbuf;
};
@@
-74,25
+73,22
@@
struct rsapub {
static const char *hexchars="0123456789abcdef";
static const char *hexchars="0123456789abcdef";
-static void rsa_sethash(struct rsacommon *c, struct hash_if *hash)
+static void rsa_sethash(struct rsacommon *c, struct hash_if *hash,
+ const struct hash_if **in_ops)
{
free(c->hashbuf);
c->hashbuf=safe_malloc(hash->hlen, "generate_msg");
{
free(c->hashbuf);
c->hashbuf=safe_malloc(hash->hlen, "generate_msg");
-
c->hashi
=hash;
+
*in_ops
=hash;
}
static void rsa_pub_sethash(void *sst, struct hash_if *hash)
{
struct rsapub *st=sst;
}
static void rsa_pub_sethash(void *sst, struct hash_if *hash)
{
struct rsapub *st=sst;
- rsa_sethash(&st->common, hash);
+ rsa_sethash(&st->common, hash
, &st->ops.hash
);
}
static void rsa_priv_sethash(void *sst, struct hash_if *hash)
{
struct rsapriv *st=sst;
}
static void rsa_priv_sethash(void *sst, struct hash_if *hash)
{
struct rsapriv *st=sst;
- rsa_sethash(&st->common, hash);
-}
-static void rsa_hash(struct rsacommon *c, const uint8_t *buf, int32_t len)
-{
- hash_hash(c->hashi,buf,len,c->hashbuf);
+ rsa_sethash(&st->common, hash, &st->ops.hash);
}
static void emsa_pkcs1(MP_INT *n, MP_INT *m,
}
static void emsa_pkcs1(MP_INT *n, MP_INT *m,
@@
-154,9
+150,9
@@
static bool_t rsa_sign(void *sst, uint8_t *data, int32_t datalen,
mpz_init(&a);
mpz_init(&b);
mpz_init(&a);
mpz_init(&b);
-
rsa_hash(&st->common,data,datalen
);
+
hash_hash(st->ops.hash,data,datalen,st->common.hashbuf
);
/* Construct the message representative. */
/* Construct the message representative. */
- emsa_pkcs1(&st->n, &a, st->common.hashbuf, st->
common.hashi
->hlen);
+ emsa_pkcs1(&st->n, &a, st->common.hashbuf, st->
ops.hash
->hlen);
/*
* Produce an RSA signature (a^d mod n) using the Chinese
/*
* Produce an RSA signature (a^d mod n) using the Chinese
@@
-242,8
+238,8
@@
static bool_t rsa_sig_check(void *sst, uint8_t *data, int32_t datalen,
mpz_init(&b);
mpz_init(&c);
mpz_init(&b);
mpz_init(&c);
-
rsa_hash(&st->common,data,datalen
);
- emsa_pkcs1(&st->n, &a, st->common.hashbuf, st->
common.hashi
->hlen);
+
hash_hash(st->ops.hash,data,datalen,st->common.hashbuf
);
+ emsa_pkcs1(&st->n, &a, st->common.hashbuf, st->
ops.hash
->hlen);
/* Terminate signature with a '0' - already checked that this will fit */
int save = sig->start[sig->len];
/* Terminate signature with a '0' - already checked that this will fit */
int save = sig->start[sig->len];
@@
-279,6
+275,8
@@
static list_t *rsapub_apply(closure_t *self, struct cloc loc, dict_t *context,
st->common.hashbuf=NULL;
st->ops.unpick=rsa_sig_unpick;
st->ops.check=rsa_sig_check;
st->common.hashbuf=NULL;
st->ops.unpick=rsa_sig_unpick;
st->ops.check=rsa_sig_check;
+ st->ops.hash=0;
+ st->ops.dispose=0; /* xxx */
st->loc=loc;
i=list_elem(args,0);
st->loc=loc;
i=list_elem(args,0);
@@
-359,6
+357,8
@@
static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
st->ops.sethash=rsa_priv_sethash;
st->common.hashbuf=NULL;
st->ops.sign=rsa_sign;
st->ops.sethash=rsa_priv_sethash;
st->common.hashbuf=NULL;
st->ops.sign=rsa_sign;
+ st->ops.hash=0;
+ st->ops.dispose=0; /* xxx */
st->loc=loc;
/* Argument is filename pointing to SSH1 private key file */
st->loc=loc;
/* Argument is filename pointing to SSH1 private key file */