summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-05-07 02:13:23 +0000
committerNick Mathewson <nickm@torproject.org>2003-05-07 02:13:23 +0000
commitd0ff485e1b36e07d1edecdc6c454d636dea99061 (patch)
tree58542df3aabc3430143d1b22320885df116c137d /src/common
parent3416a106273b419eda949febe70aa23b15af4ac5 (diff)
downloadtor-d0ff485e1b36e07d1edecdc6c454d636dea99061.tar.gz
tor-d0ff485e1b36e07d1edecdc6c454d636dea99061.zip
More work on directories. Signed directories not yet tested. No support for checking sigs yet
svn:r268
Diffstat (limited to 'src/common')
-rw-r--r--src/common/crypto.c65
-rw-r--r--src/common/crypto.h5
2 files changed, 70 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index e200550acb..ad05b2666c 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -545,6 +545,36 @@ int crypto_pk_private_decrypt(crypto_pk_env_t *env, unsigned char *from, int fro
}
}
+int crypto_pk_public_checksig(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to)
+{
+ assert(env && from && to);
+
+ switch(env->type) {
+ case CRYPTO_PK_RSA:
+ if (!(((RSA*)env->key)->p))
+ return -1;
+ return RSA_public_decrypt(fromlen, from, to, (RSA *)env->key,
+ RSA_PKCS1_OAEP_PADDING);
+ default:
+ return -1;
+ }
+}
+
+int crypto_pk_private_sign(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to)
+{
+ assert(env && from && to);
+
+ switch(env->type) {
+ case CRYPTO_PK_RSA:
+ if (!(((RSA*)env->key)->p))
+ return -1;
+ return RSA_private_encrypt(fromlen, from, to, (RSA *)env->key,
+ RSA_PKCS1_OAEP_PADDING);
+ default:
+ return -1;
+ }
+}
+
/* symmetric crypto */
int crypto_cipher_generate_key(crypto_cipher_env_t *env)
{
@@ -779,3 +809,38 @@ char *crypto_perror()
return (char *)ERR_reason_error_string(ERR_get_error());
}
+int
+base64_encode(char *dest, int destlen, char *src, int srclen)
+{
+ EVP_ENCODE_CTX ctx;
+ int len, ret;
+
+ /* 48 bytes of input -> 64 bytes of output plus newline.
+ Plus one more byte, in case I'm wrong.
+ */
+ if (destlen < ((srclen/48)+1)*66)
+ return -1;
+
+ EVP_EncodeInit(&ctx);
+ EVP_EncodeUpdate(&ctx, dest, &len, src, srclen);
+ EVP_EncodeFinal(&ctx, dest, &ret);
+ ret += len;
+ return ret;
+}
+int
+base64_decode(char *dest, int destlen, char *src, int srclen)
+{
+ EVP_ENCODE_CTX ctx;
+ int len, ret;
+ /* 64 bytes of input -> *up to* 48 bytes of output.
+ Plus one more byte, in caes I'm wrong.
+ */
+ if (destlen < ((srclen/64)+1)*49)
+ return -1;
+
+ EVP_DecodeInit(&ctx);
+ EVP_DecodeUpdate(&ctx, dest, &len, src, srclen);
+ EVP_DecodeFinal(&ctx, dest, &ret);
+ ret += len;
+ return ret;
+}
diff --git a/src/common/crypto.h b/src/common/crypto.h
index af0cc904c2..d5cfdb55e1 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -64,6 +64,11 @@ int crypto_pk_keysize(crypto_pk_env_t *env);
int crypto_pk_public_encrypt(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to, int padding);
int crypto_pk_private_decrypt(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to, int padding);
+int crypto_pk_private_sign(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to);
+int crypto_pk_private_checksig(crypto_pk_env_t *env, unsigned char *from, int fromlen, unsigned char *to);
+
+int base64_encode(char *dest, int destlen, char *src, int srclen);
+int base64_decode(char *dest, int destlen, char *src, int srclen);
/* Key negotiation */
typedef struct crypto_dh_env_st crypto_dh_env_t;