[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] More work on directories. Signed directories not yet teste...
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv16444/src/common
Modified Files:
crypto.c crypto.h
Log Message:
More work on directories. Signed directories not yet tested. No support for checking sigs yet
Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- crypto.c 1 May 2003 00:53:46 -0000 1.15
+++ crypto.c 7 May 2003 02:13:23 -0000 1.16
@@ -545,6 +545,36 @@
}
}
+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 @@
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;
+}
Index: crypto.h
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- crypto.h 1 May 2003 00:53:46 -0000 1.8
+++ crypto.h 7 May 2003 02:13:23 -0000 1.9
@@ -64,6 +64,11 @@
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;