version 1.14, 2002/02/28 15:46:33 |
version 1.14.2.2, 2002/10/11 14:51:53 |
|
|
#define SIGBLOB_LEN (2*INTBLOB_LEN) |
#define SIGBLOB_LEN (2*INTBLOB_LEN) |
|
|
int |
int |
ssh_dss_sign( |
ssh_dss_sign(Key *key, u_char **sigp, u_int *lenp, |
Key *key, |
|
u_char **sigp, u_int *lenp, |
|
u_char *data, u_int datalen) |
u_char *data, u_int datalen) |
{ |
{ |
DSA_SIG *sig; |
DSA_SIG *sig; |
const EVP_MD *evp_md = EVP_sha1(); |
const EVP_MD *evp_md = EVP_sha1(); |
EVP_MD_CTX md; |
EVP_MD_CTX md; |
u_char *ret, digest[EVP_MAX_MD_SIZE], sigblob[SIGBLOB_LEN]; |
u_char digest[EVP_MAX_MD_SIZE], sigblob[SIGBLOB_LEN]; |
u_int rlen, slen, len, dlen; |
u_int rlen, slen, len, dlen; |
Buffer b; |
Buffer b; |
|
|
|
|
rlen = BN_num_bytes(sig->r); |
rlen = BN_num_bytes(sig->r); |
slen = BN_num_bytes(sig->s); |
slen = BN_num_bytes(sig->s); |
if (rlen > INTBLOB_LEN || slen > INTBLOB_LEN) { |
if (rlen > INTBLOB_LEN || slen > INTBLOB_LEN) { |
error("bad sig size %d %d", rlen, slen); |
error("bad sig size %u %u", rlen, slen); |
DSA_SIG_free(sig); |
DSA_SIG_free(sig); |
return -1; |
return -1; |
} |
} |
|
|
DSA_SIG_free(sig); |
DSA_SIG_free(sig); |
|
|
if (datafellows & SSH_BUG_SIGBLOB) { |
if (datafellows & SSH_BUG_SIGBLOB) { |
ret = xmalloc(SIGBLOB_LEN); |
|
memcpy(ret, sigblob, SIGBLOB_LEN); |
|
if (lenp != NULL) |
if (lenp != NULL) |
*lenp = SIGBLOB_LEN; |
*lenp = SIGBLOB_LEN; |
if (sigp != NULL) |
if (sigp != NULL) { |
*sigp = ret; |
*sigp = xmalloc(SIGBLOB_LEN); |
|
memcpy(*sigp, sigblob, SIGBLOB_LEN); |
|
} |
} else { |
} else { |
/* ietf-drafts */ |
/* ietf-drafts */ |
buffer_init(&b); |
buffer_init(&b); |
buffer_put_cstring(&b, "ssh-dss"); |
buffer_put_cstring(&b, "ssh-dss"); |
buffer_put_string(&b, sigblob, SIGBLOB_LEN); |
buffer_put_string(&b, sigblob, SIGBLOB_LEN); |
len = buffer_len(&b); |
len = buffer_len(&b); |
ret = xmalloc(len); |
|
memcpy(ret, buffer_ptr(&b), len); |
|
buffer_free(&b); |
|
if (lenp != NULL) |
if (lenp != NULL) |
*lenp = len; |
*lenp = len; |
if (sigp != NULL) |
if (sigp != NULL) { |
*sigp = ret; |
*sigp = xmalloc(len); |
|
memcpy(*sigp, buffer_ptr(&b), len); |
|
} |
|
buffer_free(&b); |
} |
} |
return 0; |
return 0; |
} |
} |
int |
int |
ssh_dss_verify( |
ssh_dss_verify(Key *key, u_char *signature, u_int signaturelen, |
Key *key, |
|
u_char *signature, u_int signaturelen, |
|
u_char *data, u_int datalen) |
u_char *data, u_int datalen) |
{ |
{ |
DSA_SIG *sig; |
DSA_SIG *sig; |
|
|
} |
} |
|
|
if (len != SIGBLOB_LEN) { |
if (len != SIGBLOB_LEN) { |
fatal("bad sigbloblen %d != SIGBLOB_LEN", len); |
fatal("bad sigbloblen %u != SIGBLOB_LEN", len); |
} |
} |
|
|
/* parse signature */ |
/* parse signature */ |