1 #ifdef HAVE_DIX_CONFIG_H
2 #include <dix-config.h>
8 #if defined(HAVE_SHA1_IN_LIBMD) /* Use libmd for SHA1 */ \
9 || defined(HAVE_SHA1_IN_LIBC) /* Use libc for SHA1 */
16 SHA1_CTX
*ctx
= malloc(sizeof(*ctx
));
25 x_sha1_update(void *ctx
, void *data
, int size
)
27 SHA1_CTX
*sha1_ctx
= ctx
;
29 SHA1Update(sha1_ctx
, data
, size
);
34 x_sha1_final(void *ctx
, unsigned char result
[20])
36 SHA1_CTX
*sha1_ctx
= ctx
;
38 SHA1Final(result
, sha1_ctx
);
43 #elif defined(HAVE_SHA1_IN_COMMONCRYPTO) /* Use CommonCrypto for SHA1 */
45 #include <CommonCrypto/CommonDigest.h>
50 CC_SHA1_CTX
*ctx
= malloc(sizeof(*ctx
));
59 x_sha1_update(void *ctx
, void *data
, int size
)
61 CC_SHA1_CTX
*sha1_ctx
= ctx
;
63 CC_SHA1_Update(sha1_ctx
, data
, size
);
68 x_sha1_final(void *ctx
, unsigned char result
[20])
70 CC_SHA1_CTX
*sha1_ctx
= ctx
;
72 CC_SHA1_Final(result
, sha1_ctx
);
77 #elif defined(HAVE_SHA1_IN_CRYPTOAPI) /* Use CryptoAPI for SHA1 */
79 #define WIN32_LEAN_AND_MEAN
80 #include <X11/Xwindows.h>
83 static HCRYPTPROV hProv
;
88 HCRYPTHASH
*ctx
= malloc(sizeof(*ctx
));
92 CryptAcquireContext(&hProv
, NULL
, MS_DEF_PROV
, PROV_RSA_FULL
, CRYPT_VERIFYCONTEXT
);
93 CryptCreateHash(hProv
, CALG_SHA1
, 0, 0, ctx
);
98 x_sha1_update(void *ctx
, void *data
, int size
)
100 HCRYPTHASH
*hHash
= ctx
;
102 CryptHashData(*hHash
, data
, size
, 0);
107 x_sha1_final(void *ctx
, unsigned char result
[20])
109 HCRYPTHASH
*hHash
= ctx
;
112 CryptGetHashParam(*hHash
, HP_HASHVAL
, result
, &len
, 0);
113 CryptDestroyHash(*hHash
);
114 CryptReleaseContext(hProv
, 0);
119 #elif defined(HAVE_SHA1_IN_LIBNETTLE) /* Use libnettle for SHA1 */
121 #include <nettle/sha.h>
126 struct sha1_ctx
*ctx
= malloc(sizeof(*ctx
));
135 x_sha1_update(void *ctx
, void *data
, int size
)
137 sha1_update(ctx
, size
, data
);
142 x_sha1_final(void *ctx
, unsigned char result
[20])
144 sha1_digest(ctx
, 20, result
);
149 #elif defined(HAVE_SHA1_IN_LIBGCRYPT) /* Use libgcrypt for SHA1 */
161 if (!gcry_check_version(NULL
))
163 gcry_control(GCRYCTL_DISABLE_SECMEM
, 0);
164 gcry_control(GCRYCTL_INITIALIZATION_FINISHED
, 0);
168 err
= gcry_md_open(&h
, GCRY_MD_SHA1
, 0);
175 x_sha1_update(void *ctx
, void *data
, int size
)
177 gcry_md_hd_t h
= ctx
;
179 gcry_md_write(h
, data
, size
);
184 x_sha1_final(void *ctx
, unsigned char result
[20])
186 gcry_md_hd_t h
= ctx
;
188 memcpy(result
, gcry_md_read(h
, GCRY_MD_SHA1
), 20);
193 #elif defined(HAVE_SHA1_IN_LIBSHA1) /* Use libsha1 */
200 sha1_ctx
*ctx
= malloc(sizeof(*ctx
));
209 x_sha1_update(void *ctx
, void *data
, int size
)
211 sha1_hash(data
, size
, ctx
);
216 x_sha1_final(void *ctx
, unsigned char result
[20])
218 sha1_end(result
, ctx
);
223 #else /* Use OpenSSL's libcrypto */
225 #include <stddef.h> /* buggy openssl/sha.h wants size_t */
226 #include <openssl/sha.h>
232 SHA_CTX
*ctx
= malloc(sizeof(*ctx
));
236 ret
= SHA1_Init(ctx
);
245 x_sha1_update(void *ctx
, void *data
, int size
)
248 SHA_CTX
*sha_ctx
= ctx
;
250 ret
= SHA1_Update(sha_ctx
, data
, size
);
257 x_sha1_final(void *ctx
, unsigned char result
[20])
260 SHA_CTX
*sha_ctx
= ctx
;
262 ret
= SHA1_Final(result
, sha_ctx
);