* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* - all of EVP interface functionality minus `engine' support
* - all of PEM interface functionality
* - a simple SSL client
- *
+ *
* In addition, we are trying hard to provide not only an exact elisp
* copy of openssl, but also a _comprehensive_ one
*
- *
+ *
* * src/openssl.c: functions overview:
*
* - General
* ossl-connect - constructor for SSL connection objects
* ossl-finish - destructor of SSL connection objects
* ossl-pending - predicate if data is available for read
- * ossl-read -
+ * ossl-read -
* ossl-write -
* ossl-x509-get-subject
* ossl-x509-get-issuer
* ossl-sslcipher-name
* ossl-sslcipher-bits
*
- *
+ *
* * Todo (internally):
* - implement the usage of engines
* - implement X.509 stuff
* (ossl-ec-pkey-p pkey)
* ;; generate an ec (elliptic curve) key
* ;; Note: this is probably disabled in your openssl
- * (when (featurep 'openssl-ec)
+ * (when (featurep 'openssl-ec)
* (setq pkey (ossl-ec-generate-key))
* (ossl-ec-pkey-p pkey))
*
* Note: For these functions you must have enabled DH in your OpenSSL lib
* ;; not yet
*
- * - HYBRID
+ * - HYBRID
* (setq key (ossl-rsa-generate-key 2048 3))
* (setq enc (ossl-seal 'AES-256-ECB "a tight secret" key))
* (ossl-open 'AES-256-ECB (car enc) key (cadr enc) (caddr enc))
/*
*
* AUXILIARY
- *
+ *
*/
DEFUN("ossl-version", Fossl_version, 0, 0, 0, /*
Return a descriptive version number of the OpenSSL in use.
#define ossl_digest_fun(var, fun) \
-{ \
+do { \
int __kl; \
const EVP_MD *__md; \
\
if (!__md) { \
EVP_cleanup(); \
return -1; \
- } \
+ } \
\
__kl = fun(__md); \
\
#define ossl_cipher_fun(var, fun) \
-{ \
+do { \
int __kl; \
const EVP_CIPHER *__ciph; \
\
if (!__ciph) { \
EVP_cleanup(); \
return -1; \
- } \
+ } \
\
__kl = fun(__ciph); \
\
\f
/*
- *
+ *
* RAND
- *
+ *
*/
DEFUN("ossl-rand-bytes", Fossl_rand_bytes, 1, 1, 0, /*
Return COUNT bytes of randomness.
file = Fexpand_file_name(file, Qnil);
if (((fp = fopen((char *)XSTRING_DATA(file),"rb")) == NULL) ||
- (fseek(fp, 0, SEEK_SET)))
+ (fseek(fp, 0, SEEK_SET))) {
+ if (fp)
+ fclose(fp);
return wrong_type_argument(Qfile_readable_p, file);
-
+ }
OpenSSL_add_all_digests();
md = EVP_get_digestbyname(
if (!md) {
EVP_cleanup();
+ fclose(fp);
error ("no such digest");
}
mdctx = xnew(EVP_MD_CTX);
EVP_MD_CTX_init(mdctx);
md_blocksize = (unsigned int)(EVP_MD_block_size(md) / 8);
+ SXE_SET_UNUSED(md_blocksize);
EVP_DigestInit_ex(mdctx, md, NULL);
return Qnil;
}
EVP_DigestUpdate(mdctx, md_value, n);
- } while (n > 0);
+ } while (n > 0);
EVP_DigestFinal_ex(mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup(mdctx);
}
-/*
+/*
*
* HMAC (aka keyed hashes)
- *
+ *
*/
DEFUN("ossl-hmac", Fossl_hmac, 3, 3, 0, /*
Return the message authentication code of MSG
return Qnil;
}
HMAC_Update(hmacctx, outbuf, n);
- } while (n > 0);
+ } while (n > 0);
HMAC_Final(hmacctx, outbuf, &outlen);
HMAC_CTX_cleanup(hmacctx);
}
-/*
- *
+/*
+ *
* SYMMETRIC CIPHER
- *
+ *
*/
DEFUN("ossl-bytes-to-key", Fossl_bytes_to_key, 5, 5, 0, /*
Derive a key and initialisation vector (iv) suitable for a cipher.
COUNT \(a positive integer\) is the iteration count to use. This
indicates how often the hash algorithm is called recursively.
-Note: You probably want to put a wrapping encoder function
+Note: You probably want to put a wrapping encoder function
\(like `base16-encode-string'\) around it, since this returns
binary string data.
*/
STRING is the text to be encrypted.
-KEY should be a key generated suitably for this cipher, for example
+KEY should be a key generated suitably for this cipher, for example
by `ossl-bytes-to-key'.
Optional fourth argument IV should be an initialisation vector
}
fseek(fp, 0, SEEK_END);
- file_size = ftell(fp);
+ file_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
C_STRING_ALLOCA, string_ext, OSSL_CODING);
string_len = OSSL_STRING_LENGTH(string);
- if (!string_len)
+ if (!string_len)
error ("string must be of non-zero positive length.");
OpenSSL_add_all_algorithms();
}
fseek(fp, 0, SEEK_END);
- file_size = ftell(fp);
+ file_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
}
-/*
- *
+/*
+ *
* ASYMMETRIC CIPHER
- *
+ *
*/
/* This is an opaque object for storing PKEYs in lisp */
Lisp_Object Qevp_pkeyp;
static void
print_evp_pkey(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
- char buf[256];
EVP_PKEY *pkey;
X509 *x509;
if (x509) {
X509_NAME *iss = X509_get_issuer_name(x509);
X509_NAME *sub = X509_get_subject_name(x509);
- write_c_string(" X509 Certificate", printcharfun);
+ write_c_string(" X509 Certificate", printcharfun);
write_c_string(" iss:", printcharfun);
write_c_string(X509_NAME_oneline(sub, NULL, 0), printcharfun);
write_c_string(" sub:", printcharfun);
write_c_string(";", printcharfun);
if (rsa_pkey_p(pkey))
- write_c_string(" RSA", printcharfun);
+ write_c_string(" RSA", printcharfun);
else if (dsa_pkey_p(pkey))
- write_c_string(" DSA", printcharfun);
+ write_c_string(" DSA", printcharfun);
else if (ec_pkey_p(pkey))
- write_c_string(" EC", printcharfun);
+ write_c_string(" EC", printcharfun);
if (ossl_pkey_has_private_data(pkey))
- write_c_string(" private/public key", printcharfun);
+ write_c_string(" private/public key", printcharfun);
else if (ossl_pkey_has_public_data(pkey))
- write_c_string(" public key", printcharfun);
+ write_c_string(" public key", printcharfun);
&nb