X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=crypt.c;h=b754c0919e6fbccca77c0d662bddf59c6351fca6;hp=5b7029d32d1aa906b8d5dae49a0e965af9d1c87f;hb=2830b9f881898aaec073d5ba19e33482e30190bd;hpb=c0abcee0da53a6b399c3d16a62830aaa9ae21349 diff --git a/crypt.c b/crypt.c index 5b7029d3..b754c091 100644 --- a/crypt.c +++ b/crypt.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Andre Noll + * Copyright (C) 2005-2012 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -7,7 +7,6 @@ /** \file crypt.c Openssl-based encryption/decryption routines. */ #include -#include #include #include #include @@ -184,24 +183,25 @@ int get_asymmetric_key(const char *key_file, int private, PARA_INFO_LOG("decoding public rsa-ssh key %s\n", key_file); ret = -ERRNO_TO_PARA_ERROR(EOVERFLOW); if (map_size > INT_MAX / 4) - goto out; + goto out_unmap; blob_size = 2 * map_size; blob = para_malloc(blob_size); ret = uudecode(cp, blob, blob_size); if (ret < 0) - goto out; + goto out_unmap; decoded_size = ret; ret = check_ssh_key_header(blob, decoded_size); if (ret < 0) - goto out; + goto out_unmap; ret = read_rsa_bignums(blob + ret, decoded_size - ret, &key->rsa); if (ret < 0) - goto out; + goto out_unmap; ret = RSA_size(key->rsa); -out: +out_unmap: ret2 = para_munmap(map, map_size); if (ret >= 0 && ret2 < 0) ret = ret2; +out: if (ret < 0) { free(key); *result = NULL; @@ -298,7 +298,7 @@ int sc_send_bin_buffer(struct stream_cipher_context *scc, char *buf, memcpy(remainder, buf + l1, len - l1); RC4(&scc->send->key, len - l1, remainder, tmp + l1); } - ret = write_all(scc->fd, (char *)tmp, &len); + ret = xwrite(scc->fd, (char *)tmp, len); free(tmp); return ret; } @@ -306,7 +306,7 @@ int sc_send_bin_buffer(struct stream_cipher_context *scc, char *buf, int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf, size_t size) { - unsigned char *tmp = para_malloc(size); + unsigned char *tmp = para_malloc(ROUND_UP(size, RC4_ALIGN)); ssize_t ret = recv(scc->fd, tmp, size, 0); if (ret > 0) @@ -317,6 +317,23 @@ int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf, return ret; } +void sc_crypt(struct stream_cipher *sc, struct iovec *src, struct iovec *dst) +{ + RC4_KEY *key = &sc->key; + + *dst = (typeof(*dst)) { + /* + * Add one for the terminating zero byte. Integer overflow is + * no problem here as para_malloc() aborts when given a zero + * size argument. + */ + .iov_base = para_malloc(src->iov_len + 1), + .iov_len = src->iov_len + }; + RC4(key, src->iov_len, src->iov_base, dst->iov_base); + ((char *)dst->iov_base)[dst->iov_len] = '\0'; +} + void hash_function(const char *data, unsigned long len, unsigned char *hash) { SHA_CTX c;