Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 263 lines (205 sloc) 7.052 kb
d8a6a593 »
2007-06-12 Initial import
1 #include "HsOpenSSL.h"
ed5b4c2f » agl
2008-02-14 Add the beginnings of session support
2 #include <stdint.h>
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
3 #include "mutex.h"
d8a6a593 »
2007-06-12 Initial import
4
08a3dbfb »
2007-06-14 BN and RSA
5 /* OpenSSL ********************************************************************/
014bbd02 »
2007-06-15 RSA keys can now be written to an BIO.
6 void HsOpenSSL_OpenSSL_add_all_algorithms() {
7 OpenSSL_add_all_algorithms();
8 }
9
08a3dbfb »
2007-06-14 BN and RSA
10 void HsOpenSSL_OPENSSL_free(void* ptr) {
11 OPENSSL_free(ptr);
12 }
13
eb4af72e »
2007-06-14 Many improvements
14 /* BIO ************************************************************************/
15 void HsOpenSSL_BIO_set_flags(BIO* bio, int flags) {
16 BIO_set_flags(bio, flags);
17 }
18
19 int HsOpenSSL_BIO_flush(BIO* bio) {
20 return BIO_flush(bio);
21 }
22
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
23 int HsOpenSSL_BIO_reset(BIO* bio) {
24 return BIO_reset(bio);
25 }
26
eb4af72e »
2007-06-14 Many improvements
27 int HsOpenSSL_BIO_eof(BIO* bio) {
d8a6a593 »
2007-06-12 Initial import
28 return BIO_eof(bio);
29 }
eb4af72e »
2007-06-14 Many improvements
30
31 int HsOpenSSL_BIO_set_md(BIO* bio, EVP_MD* md) {
32 return BIO_set_md(bio, md);
33 }
34
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
35 int HsOpenSSL_BIO_set_buffer_size(BIO* bio, int bufSize) {
36 return BIO_set_buffer_size(bio, bufSize);
37 }
38
39 int HsOpenSSL_BIO_should_retry(BIO* bio) {
40 return BIO_should_retry(bio);
41 }
42
eb4af72e »
2007-06-14 Many improvements
43 int HsOpenSSL_BIO_FLAGS_BASE64_NO_NL() {
44 return BIO_FLAGS_BASE64_NO_NL;
45 }
46
b4df65b6 »
2011-09-22 DHparams_dup() is a function in OpenSSL 1.0.0 but is a macro in 0.9.8.
47 /* DH *************************************************************************/
48 DH* HsOpenSSL_DHparams_dup(DH* dh) {
49 return DHparams_dup(dh);
50 }
51
eb4af72e »
2007-06-14 Many improvements
52 /* EVP ************************************************************************/
53 int HsOpenSSL_EVP_MD_size(EVP_MD* md) {
54 return EVP_MD_size(md);
55 }
0d5c5002 »
2007-06-16 OpenSSL.EVP.Verify and others
56
57 int HsOpenSSL_EVP_CIPHER_CTX_block_size(EVP_CIPHER_CTX* ctx) {
58 return EVP_CIPHER_CTX_block_size(ctx);
59 }
addcae06 »
2007-06-17 OpenSSL.EVP.Open and OpenSSL.EVP.Seal
60
61 int HsOpenSSL_EVP_CIPHER_iv_length(EVP_CIPHER* cipher) {
62 return EVP_CIPHER_iv_length(cipher);
63 }
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
64
2ccb13d5 »
2007-06-20 OpenSSL.X509
65 /* X509 ***********************************************************************/
66 long HsOpenSSL_X509_get_version(X509* x509) {
67 return X509_get_version(x509);
68 }
69
70 ASN1_TIME* HsOpenSSL_X509_get_notBefore(X509* x509) {
71 return X509_get_notBefore(x509);
72 }
73
74 ASN1_TIME* HsOpenSSL_X509_get_notAfter(X509* x509) {
75 return X509_get_notAfter(x509);
76 }
77
36ab1882 »
2007-06-22 OpenSSL.X509.Request
78 long HsOpenSSL_X509_REQ_get_version(X509_REQ* req) {
79 return X509_REQ_get_version(req);
80 }
81
82 X509_NAME* HsOpenSSL_X509_REQ_get_subject_name(X509_REQ* req) {
83 return X509_REQ_get_subject_name(req);
84 }
85
6423c00c »
2007-06-23 OpenSSL.X509.Revocation
86 long HsOpenSSL_X509_CRL_get_version(X509_CRL* crl) {
87 return X509_CRL_get_version(crl);
88 }
89
90 ASN1_TIME* HsOpenSSL_X509_CRL_get_lastUpdate(X509_CRL* crl) {
91 return X509_CRL_get_lastUpdate(crl);
92 }
93
94 ASN1_TIME* HsOpenSSL_X509_CRL_get_nextUpdate(X509_CRL* crl) {
95 return X509_CRL_get_nextUpdate(crl);
96 }
97
98 X509_NAME* HsOpenSSL_X509_CRL_get_issuer(X509_CRL* crl) {
99 return X509_CRL_get_issuer(crl);
100 }
101
102 STACK_OF(X509_REVOKED)* HsOpenSSL_X509_CRL_get_REVOKED(X509_CRL* crl) {
103 return X509_CRL_get_REVOKED(crl);
104 }
105
93671718 » mvv
2012-04-16 Bindings to some of the X509_STORE_CTX functions.
106 void HsOpenSSL_X509_ref(X509* x509) {
107 CRYPTO_add(&x509->references, 1, CRYPTO_LOCK_X509);
108 }
109
110 void HsOpenSSL_X509_CRL_ref(X509_CRL* crl) {
111 CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509_CRL);
112 }
2fb4c2a2 »
2007-06-30 PKCS#7 (en|de)cryption
113
392a75fb » mvv
2012-04-22 Fixed X509_STORE_CTX bindings vs OpenSSL 0.9.x
114 X509* HsOpenSSL_X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx) {
115 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
116 return X509_STORE_CTX_get0_current_issuer(ctx);
117 #else
118 return ctx->current_issuer;
119 #endif
120 }
121
122 X509_CRL* HsOpenSSL_X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx) {
123 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
124 return X509_STORE_CTX_get0_current_crl(ctx);
125 #else
126 return ctx->current_crl;
127 #endif
128 }
129
2fb4c2a2 »
2007-06-30 PKCS#7 (en|de)cryption
130 /* PKCS#7 *********************************************************************/
131 long HsOpenSSL_PKCS7_is_detached(PKCS7* pkcs7) {
132 return PKCS7_is_detached(pkcs7);
133 }
134
135
defa84f2 » mvv
2011-08-15 Added bindings to Diffie-Hellman functions.
136 /* DH *************************************************************************/
137 BIGNUM *HsOpenSSL_DH_get_pub_key(DH *dh) {
138 return dh->pub_key;
139 }
140
141 int HsOpenSSL_DH_length(DH *dh) {
142 return BN_num_bits(dh->p);
143 }
144
145
5f8ccf00 »
2007-06-21 OpenSSL.X509 can now create and sign X.509 certificate!
146 /* ASN1 ***********************************************************************/
147 ASN1_INTEGER* HsOpenSSL_M_ASN1_INTEGER_new() {
148 return M_ASN1_INTEGER_new();
149 }
150
151 void HsOpenSSL_M_ASN1_INTEGER_free(ASN1_INTEGER* intPtr) {
152 M_ASN1_INTEGER_free(intPtr);
153 }
154
155 ASN1_INTEGER* HsOpenSSL_M_ASN1_TIME_new() {
156 return M_ASN1_TIME_new();
157 }
158
159 void HsOpenSSL_M_ASN1_TIME_free(ASN1_TIME* timePtr) {
160 M_ASN1_TIME_free(timePtr);
161 }
162
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
163 /* Threads ********************************************************************/
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
164 static mutex_t* mutex_at;
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
165
166 struct CRYPTO_dynlock_value {
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
167 mutex_t mutex;
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
168 };
169
170 static void HsOpenSSL_lockingCallback(int mode, int n, const char* file, int line) {
171 if (mode & CRYPTO_LOCK) {
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
172 mutex_lock(&mutex_at[n]);
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
173 }
174 else {
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
175 mutex_unlock(&mutex_at[n]);
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
176 }
177 }
178
179 static unsigned long HsOpenSSL_idCallback() {
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
180 return (unsigned long)self();
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
181 }
182
183 static struct CRYPTO_dynlock_value* HsOpenSSL_dynlockCreateCallback(const char* file, int line) {
184 struct CRYPTO_dynlock_value* val;
185
186 val = OPENSSL_malloc(sizeof(struct CRYPTO_dynlock_value));
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
187 mutex_init(&val->mutex);
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
188
189 return val;
190 }
191
192 static void HsOpenSSL_dynlockLockCallback(int mode, struct CRYPTO_dynlock_value* val, const char* file, int line) {
193 if (mode & CRYPTO_LOCK) {
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
194 mutex_lock(&val->mutex);
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
195 }
196 else {
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
197 mutex_unlock(&val->mutex);
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
198 }
199 }
200
201 static void HsOpenSSL_dynlockDestroyCallback(struct CRYPTO_dynlock_value* val, const char* file, int line) {
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
202 mutex_destroy(&val->mutex);
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
203 OPENSSL_free(val);
204 }
205
206 void HsOpenSSL_setupMutex() {
207 int i;
208
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
209 mutex_at = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(*mutex_at));
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
210
211 for (i = 0; i < CRYPTO_num_locks(); i++) {
e91ca160 »
2009-06-27 Applied a patch from John Van Enk and his friend.
212 mutex_init(&mutex_at[i]);
df272248 »
2007-06-19 Implemented OpenSSL.EVP.Base64 / Buried OpenSSL.BIO
213 }
214
215 CRYPTO_set_locking_callback(HsOpenSSL_lockingCallback);
216 CRYPTO_set_id_callback(HsOpenSSL_idCallback);
217
218 CRYPTO_set_dynlock_create_callback(HsOpenSSL_dynlockCreateCallback);
219 CRYPTO_set_dynlock_lock_callback(HsOpenSSL_dynlockLockCallback);
220 CRYPTO_set_dynlock_destroy_callback(HsOpenSSL_dynlockDestroyCallback);
221 }
222
119138e9 » agl
2007-10-14 Add DSA support
223 /* DSA ************************************************************************/
224
225 /* OpenSSL sadly wants to ASN1 encode the resulting bignums so we use this
226 * function to skip that. Returns > 0 on success */
227 int HsOpenSSL_dsa_sign(DSA *dsa, const unsigned char *ddata, int dlen,
228 BIGNUM **r, BIGNUM **s) {
229 DSA_SIG *const sig = dsa->meth->dsa_do_sign(ddata, dlen, dsa);
230 if (!sig) return 0;
231 *r = sig->r;
232 *s = sig->s;
233 free(sig);
234 return 1;
235 }
236
237 int HsOpenSSL_dsa_verify(DSA *dsa, const unsigned char *ddata, int dlen,
238 BIGNUM *r, BIGNUM *s) {
239 DSA_SIG sig;
240 sig.r = r;
241 sig.s = s;
242 return dsa->meth->dsa_do_verify(ddata, dlen, &sig, dsa);
243 }
5d1dd45e »
2009-03-27 Increase type-safety of asymmetric key pairs.
244
245 #if !defined(DSAPublicKey_dup)
246 # define DSAPublicKey_dup(dsa) \
247 (DSA *)ASN1_dup((i2d_of_void *)i2d_DSAPublicKey, \
248 (d2i_of_void *)d2i_DSAPublicKey,(char *)dsa)
249 #endif
250
251 #if !defined(DSAPrivateKey_dup)
252 #define DSAPrivateKey_dup(dsa) \
253 (DSA *)ASN1_dup((i2d_of_void *)i2d_DSAPrivateKey, \
254 (d2i_of_void *)d2i_DSAPrivateKey,(char *)dsa)
255 #endif
256
257 DSA* HsOpenSSL_DSAPublicKey_dup(const DSA* dsa) {
258 return DSAPublicKey_dup(dsa);
259 }
260
261 DSA* HsOpenSSL_DSAPrivateKey_dup(const DSA* dsa) {
262 return DSAPrivateKey_dup(dsa);
263 }
Something went wrong with that request. Please try again.