X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=gcrypt.c;h=68f80f27fc30ff70fed05d5a7f7f8c89ef995260;hb=c9d82ed7bf01e5fb21e530ba819915a984e9efc4;hp=506f0bb84e6c199d065942553935dc27a8833d93;hpb=5d72d5880a6bd319a8ce2bf7dd2e4921938c77c2;p=paraslash.git diff --git a/gcrypt.c b/gcrypt.c index 506f0bb8..68f80f27 100644 --- a/gcrypt.c +++ b/gcrypt.c @@ -114,7 +114,7 @@ void crypt_shutdown(void) struct asymmetric_key { gcry_sexp_t sexp; - int num_bytes; + int bits; }; static const char *gcrypt_strerror(gcry_error_t gret) @@ -406,7 +406,7 @@ static int get_private_key(const char *key_file, struct asymmetric_key **result) ret = -E_SEXP_BUILD; goto free_params; } - key = para_malloc(sizeof(*key)); + key = alloc(sizeof(*key)); key->sexp = sexp; *result = key; ret = bits; @@ -456,11 +456,11 @@ int apc_get_pubkey(const char *key_file, struct asymmetric_key **result) goto release_n; } PARA_INFO_LOG("successfully read %u bit ssh public key\n", bits); - key = para_malloc(sizeof(*key)); - key->num_bytes = ret; + key = alloc(sizeof(*key)); key->sexp = sexp; + key->bits = bits; *result = key; - ret = bits; + ret = bits / 8; release_n: gcry_mpi_release(n); release_e: @@ -556,7 +556,7 @@ free_key: } int apc_pub_encrypt(struct asymmetric_key *pub, unsigned char *inbuf, - unsigned len, unsigned char *outbuf) + unsigned len, unsigned char **outbuf) { gcry_error_t gret; gcry_sexp_t pub_key, in, out, out_a; @@ -564,8 +564,7 @@ int apc_pub_encrypt(struct asymmetric_key *pub, unsigned char *inbuf, size_t nbytes; int ret; - PARA_INFO_LOG("encrypting %u byte input with %d-byte key\n", len, pub->num_bytes); - + *outbuf = NULL; /* get pub key */ pub_key = gcry_sexp_find_token(pub->sexp, "public-key", 0); if (!pub_key) @@ -594,14 +593,18 @@ int apc_pub_encrypt(struct asymmetric_key *pub, unsigned char *inbuf, ret = -E_SEXP_FIND; goto out_a_release; } - gret = gcry_mpi_print(GCRYMPI_FMT_USG, outbuf, 512 /* FIXME */, &nbytes, out_mpi); + *outbuf = alloc(pub->bits); + gret = gcry_mpi_print(GCRYMPI_FMT_USG, *outbuf, pub->bits, &nbytes, + out_mpi); if (gret) { + free(*outbuf); + *outbuf = NULL; PARA_ERROR_LOG("%s\n", gcrypt_strerror(gret)); ret = -E_SEXP_ENCRYPT; goto out_mpi_release; } PARA_INFO_LOG("encrypted buffer is %zu bytes\n", nbytes); - dump_buffer("enc buf", outbuf, nbytes); + dump_buffer("enc buf", *outbuf, nbytes); ret = nbytes; out_mpi_release: @@ -624,7 +627,7 @@ struct stream_cipher { struct stream_cipher *sc_new(const unsigned char *data, int len) { gcry_error_t gret; - struct stream_cipher *sc = para_malloc(sizeof(*sc)); + struct stream_cipher *sc = alloc(sizeof(*sc)); assert(len >= 2 * AES_CRT128_BLOCK_SIZE); gret = gcry_cipher_open(&sc->handle, GCRY_CIPHER_AES128,