16b384f39SPeter Avalos /*-
26b384f39SPeter Avalos * Copyright (c) 2003-2007 Tim Kientzle
36b384f39SPeter Avalos * Copyright (c) 2011 Andres Mejia
46b384f39SPeter Avalos * Copyright (c) 2011 Michihiro NAKAJIMA
56b384f39SPeter Avalos * All rights reserved.
66b384f39SPeter Avalos *
76b384f39SPeter Avalos * Redistribution and use in source and binary forms, with or without
86b384f39SPeter Avalos * modification, are permitted provided that the following conditions
96b384f39SPeter Avalos * are met:
106b384f39SPeter Avalos * 1. Redistributions of source code must retain the above copyright
116b384f39SPeter Avalos *    notice, this list of conditions and the following disclaimer.
126b384f39SPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright
136b384f39SPeter Avalos *    notice, this list of conditions and the following disclaimer in the
146b384f39SPeter Avalos *    documentation and/or other materials provided with the distribution.
156b384f39SPeter Avalos *
166b384f39SPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
176b384f39SPeter Avalos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
186b384f39SPeter Avalos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
196b384f39SPeter Avalos * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
206b384f39SPeter Avalos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
216b384f39SPeter Avalos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226b384f39SPeter Avalos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236b384f39SPeter Avalos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246b384f39SPeter Avalos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
256b384f39SPeter Avalos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266b384f39SPeter Avalos */
276b384f39SPeter Avalos 
286b384f39SPeter Avalos #include "archive_platform.h"
296b384f39SPeter Avalos 
306b384f39SPeter Avalos #include "archive.h"
316b384f39SPeter Avalos #include "archive_digest_private.h"
326b384f39SPeter Avalos 
336b384f39SPeter Avalos /* In particular, force the configure probe to break if it tries
346b384f39SPeter Avalos  * to test a combination of OpenSSL and libmd. */
356b384f39SPeter Avalos #if defined(ARCHIVE_CRYPTO_OPENSSL) && defined(ARCHIVE_CRYPTO_LIBMD)
366b384f39SPeter Avalos #error Cannot use both OpenSSL and libmd.
376b384f39SPeter Avalos #endif
386b384f39SPeter Avalos 
396b384f39SPeter Avalos /*
406b384f39SPeter Avalos  * Message digest functions for Windows platform.
416b384f39SPeter Avalos  */
426b384f39SPeter Avalos #if defined(ARCHIVE_CRYPTO_MD5_WIN)    ||\
436b384f39SPeter Avalos 	defined(ARCHIVE_CRYPTO_SHA1_WIN)   ||\
446b384f39SPeter Avalos 	defined(ARCHIVE_CRYPTO_SHA256_WIN) ||\
456b384f39SPeter Avalos 	defined(ARCHIVE_CRYPTO_SHA384_WIN) ||\
466b384f39SPeter Avalos 	defined(ARCHIVE_CRYPTO_SHA512_WIN)
476b384f39SPeter Avalos 
486b384f39SPeter Avalos /*
496b384f39SPeter Avalos  * Initialize a Message digest.
506b384f39SPeter Avalos  */
516b384f39SPeter Avalos static int
win_crypto_init(Digest_CTX * ctx,ALG_ID algId)526b384f39SPeter Avalos win_crypto_init(Digest_CTX *ctx, ALG_ID algId)
536b384f39SPeter Avalos {
546b384f39SPeter Avalos 
556b384f39SPeter Avalos 	ctx->valid = 0;
566b384f39SPeter Avalos 	if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL,
576b384f39SPeter Avalos 	    PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
586b384f39SPeter Avalos 		if (GetLastError() != (DWORD)NTE_BAD_KEYSET)
596b384f39SPeter Avalos 			return (ARCHIVE_FAILED);
606b384f39SPeter Avalos 		if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL,
616b384f39SPeter Avalos 		    PROV_RSA_FULL, CRYPT_NEWKEYSET))
626b384f39SPeter Avalos 			return (ARCHIVE_FAILED);
636b384f39SPeter Avalos 	}
646b384f39SPeter Avalos 
656b384f39SPeter Avalos 	if (!CryptCreateHash(ctx->cryptProv, algId, 0, 0, &ctx->hash)) {
666b384f39SPeter Avalos 		CryptReleaseContext(ctx->cryptProv, 0);
676b384f39SPeter Avalos 		return (ARCHIVE_FAILED);
686b384f39SPeter Avalos 	}
696b384f39SPeter Avalos 
706b384f39SPeter Avalos 	ctx->valid = 1;
716b384f39SPeter Avalos 	return (ARCHIVE_OK);
726b384f39SPeter Avalos }
736b384f39SPeter Avalos 
746b384f39SPeter Avalos /*
756b384f39SPeter Avalos  * Update a Message digest.
766b384f39SPeter Avalos  */
776b384f39SPeter Avalos static int
win_crypto_Update(Digest_CTX * ctx,const unsigned char * buf,size_t len)786b384f39SPeter Avalos win_crypto_Update(Digest_CTX *ctx, const unsigned char *buf, size_t len)
796b384f39SPeter Avalos {
806b384f39SPeter Avalos 
816b384f39SPeter Avalos 	if (!ctx->valid)
826b384f39SPeter Avalos 		return (ARCHIVE_FAILED);
836b384f39SPeter Avalos 
846b384f39SPeter Avalos 	CryptHashData(ctx->hash,
856b384f39SPeter Avalos 		      (unsigned char *)(uintptr_t)buf,
866b384f39SPeter Avalos 		      (DWORD)len, 0);
876b384f39SPeter Avalos 	return (ARCHIVE_OK);
886b384f39SPeter Avalos }
896b384f39SPeter Avalos 
906b384f39SPeter Avalos static int
win_crypto_Final(unsigned char * buf,size_t bufsize,Digest_CTX * ctx)916b384f39SPeter Avalos win_crypto_Final(unsigned char *buf, size_t bufsize, Digest_CTX *ctx)
926b384f39SPeter Avalos {
936b384f39SPeter Avalos 	DWORD siglen = (DWORD)bufsize;
946b384f39SPeter Avalos 
956b384f39SPeter Avalos 	if (!ctx->valid)
966b384f39SPeter Avalos 		return (ARCHIVE_FAILED);
976b384f39SPeter Avalos 
986b384f39SPeter Avalos 	CryptGetHashParam(ctx->hash, HP_HASHVAL, buf, &siglen, 0);
996b384f39SPeter Avalos 	CryptDestroyHash(ctx->hash);
1006b384f39SPeter Avalos 	CryptReleaseContext(ctx->cryptProv, 0);
1016b384f39SPeter Avalos 	ctx->valid = 0;
1026b384f39SPeter Avalos 	return (ARCHIVE_OK);
1036b384f39SPeter Avalos }
1046b384f39SPeter Avalos 
1056b384f39SPeter Avalos #endif /* defined(ARCHIVE_CRYPTO_*_WIN) */
1066b384f39SPeter Avalos 
1076b384f39SPeter Avalos 
1086b384f39SPeter Avalos /* MD5 implementations */
1096b384f39SPeter Avalos #if defined(ARCHIVE_CRYPTO_MD5_LIBC)
1106b384f39SPeter Avalos 
1116b384f39SPeter Avalos static int
__archive_md5init(archive_md5_ctx * ctx)112085658deSDaniel Fojt __archive_md5init(archive_md5_ctx *ctx)
1136b384f39SPeter Avalos {
1146b384f39SPeter Avalos   MD5Init(ctx);
1156b384f39SPeter Avalos   return (ARCHIVE_OK);
1166b384f39SPeter Avalos }
1176b384f39SPeter Avalos 
1186b384f39SPeter Avalos static int
__archive_md5update(archive_md5_ctx * ctx,const void * indata,size_t insize)119085658deSDaniel Fojt __archive_md5update(archive_md5_ctx *ctx, const void *indata,
1206b384f39SPeter Avalos     size_t insize)
1216b384f39SPeter Avalos {
1226b384f39SPeter Avalos   MD5Update(ctx, indata, insize);
1236b384f39SPeter Avalos   return (ARCHIVE_OK);
1246b384f39SPeter Avalos }
1256b384f39SPeter Avalos 
1266b384f39SPeter Avalos static int
__archive_md5final(archive_md5_ctx * ctx,void * md)127085658deSDaniel Fojt __archive_md5final(archive_md5_ctx *ctx, void *md)
1286b384f39SPeter Avalos {
1296b384f39SPeter Avalos   MD5Final(md, ctx);
1306b384f39SPeter Avalos   return (ARCHIVE_OK);
1316b384f39SPeter Avalos }
1326b384f39SPeter Avalos 
1336b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_MD5_LIBMD)
1346b384f39SPeter Avalos 
1356b384f39SPeter Avalos static int
__archive_md5init(archive_md5_ctx * ctx)136085658deSDaniel Fojt __archive_md5init(archive_md5_ctx *ctx)
1376b384f39SPeter Avalos {
1386b384f39SPeter Avalos   MD5Init(ctx);
1396b384f39SPeter Avalos   return (ARCHIVE_OK);
1406b384f39SPeter Avalos }
1416b384f39SPeter Avalos 
1426b384f39SPeter Avalos static int
__archive_md5update(archive_md5_ctx * ctx,const void * indata,size_t insize)143085658deSDaniel Fojt __archive_md5update(archive_md5_ctx *ctx, const void *indata,
1446b384f39SPeter Avalos     size_t insize)
1456b384f39SPeter Avalos {
1466b384f39SPeter Avalos   MD5Update(ctx, indata, insize);
1476b384f39SPeter Avalos   return (ARCHIVE_OK);
1486b384f39SPeter Avalos }
1496b384f39SPeter Avalos 
1506b384f39SPeter Avalos static int
__archive_md5final(archive_md5_ctx * ctx,void * md)151085658deSDaniel Fojt __archive_md5final(archive_md5_ctx *ctx, void *md)
1526b384f39SPeter Avalos {
1536b384f39SPeter Avalos   MD5Final(md, ctx);
1546b384f39SPeter Avalos   return (ARCHIVE_OK);
1556b384f39SPeter Avalos }
1566b384f39SPeter Avalos 
1576b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM)
1586b384f39SPeter Avalos 
1596b384f39SPeter Avalos static int
__archive_md5init(archive_md5_ctx * ctx)160085658deSDaniel Fojt __archive_md5init(archive_md5_ctx *ctx)
1616b384f39SPeter Avalos {
1626b384f39SPeter Avalos   CC_MD5_Init(ctx);
1636b384f39SPeter Avalos   return (ARCHIVE_OK);
1646b384f39SPeter Avalos }
1656b384f39SPeter Avalos 
1666b384f39SPeter Avalos static int
__archive_md5update(archive_md5_ctx * ctx,const void * indata,size_t insize)167085658deSDaniel Fojt __archive_md5update(archive_md5_ctx *ctx, const void *indata,
1686b384f39SPeter Avalos     size_t insize)
1696b384f39SPeter Avalos {
1706b384f39SPeter Avalos   CC_MD5_Update(ctx, indata, insize);
1716b384f39SPeter Avalos   return (ARCHIVE_OK);
1726b384f39SPeter Avalos }
1736b384f39SPeter Avalos 
1746b384f39SPeter Avalos static int
__archive_md5final(archive_md5_ctx * ctx,void * md)175085658deSDaniel Fojt __archive_md5final(archive_md5_ctx *ctx, void *md)
1766b384f39SPeter Avalos {
1776b384f39SPeter Avalos   CC_MD5_Final(md, ctx);
1786b384f39SPeter Avalos   return (ARCHIVE_OK);
1796b384f39SPeter Avalos }
1806b384f39SPeter Avalos 
181085658deSDaniel Fojt #elif defined(ARCHIVE_CRYPTO_MD5_MBEDTLS)
182085658deSDaniel Fojt 
183085658deSDaniel Fojt static int
__archive_md5init(archive_md5_ctx * ctx)184085658deSDaniel Fojt __archive_md5init(archive_md5_ctx *ctx)
185085658deSDaniel Fojt {
186085658deSDaniel Fojt   mbedtls_md5_init(ctx);
187085658deSDaniel Fojt   if (mbedtls_md5_starts_ret(ctx) == 0)
188085658deSDaniel Fojt     return (ARCHIVE_OK);
189085658deSDaniel Fojt   else
190085658deSDaniel Fojt     return (ARCHIVE_FATAL);
191085658deSDaniel Fojt }
192085658deSDaniel Fojt 
193085658deSDaniel Fojt static int
__archive_md5update(archive_md5_ctx * ctx,const void * indata,size_t insize)194085658deSDaniel Fojt __archive_md5update(archive_md5_ctx *ctx, const void *indata,
195085658deSDaniel Fojt     size_t insize)
196085658deSDaniel Fojt {
197085658deSDaniel Fojt   if (mbedtls_md5_update_ret(ctx, indata, insize) == 0)
198085658deSDaniel Fojt     return (ARCHIVE_OK);
199085658deSDaniel Fojt   else
200085658deSDaniel Fojt     return (ARCHIVE_FATAL);
201085658deSDaniel Fojt }
202085658deSDaniel Fojt 
203085658deSDaniel Fojt static int
__archive_md5final(archive_md5_ctx * ctx,void * md)204085658deSDaniel Fojt __archive_md5final(archive_md5_ctx *ctx, void *md)
205085658deSDaniel Fojt {
206085658deSDaniel Fojt   if (mbedtls_md5_finish_ret(ctx, md) == 0) {
207085658deSDaniel Fojt     mbedtls_md5_free(ctx);
208085658deSDaniel Fojt     return (ARCHIVE_OK);
209085658deSDaniel Fojt   } else {
210085658deSDaniel Fojt     mbedtls_md5_free(ctx);
211085658deSDaniel Fojt     return (ARCHIVE_FATAL);
212085658deSDaniel Fojt   }
213085658deSDaniel Fojt }
214085658deSDaniel Fojt 
2156b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_MD5_NETTLE)
2166b384f39SPeter Avalos 
2176b384f39SPeter Avalos static int
__archive_md5init(archive_md5_ctx * ctx)218085658deSDaniel Fojt __archive_md5init(archive_md5_ctx *ctx)
2196b384f39SPeter Avalos {
2206b384f39SPeter Avalos   md5_init(ctx);
2216b384f39SPeter Avalos   return (ARCHIVE_OK);
2226b384f39SPeter Avalos }
2236b384f39SPeter Avalos 
2246b384f39SPeter Avalos static int
__archive_md5update(archive_md5_ctx * ctx,const void * indata,size_t insize)225085658deSDaniel Fojt __archive_md5update(archive_md5_ctx *ctx, const void *indata,
2266b384f39SPeter Avalos     size_t insize)
2276b384f39SPeter Avalos {
2286b384f39SPeter Avalos   md5_update(ctx, insize, indata);
2296b384f39SPeter Avalos   return (ARCHIVE_OK);
2306b384f39SPeter Avalos }
2316b384f39SPeter Avalos 
2326b384f39SPeter Avalos static int
__archive_md5final(archive_md5_ctx * ctx,void * md)233085658deSDaniel Fojt __archive_md5final(archive_md5_ctx *ctx, void *md)
2346b384f39SPeter Avalos {
2356b384f39SPeter Avalos   md5_digest(ctx, MD5_DIGEST_SIZE, md);
2366b384f39SPeter Avalos   return (ARCHIVE_OK);
2376b384f39SPeter Avalos }
2386b384f39SPeter Avalos 
2396b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL)
2406b384f39SPeter Avalos 
2416b384f39SPeter Avalos static int
__archive_md5init(archive_md5_ctx * ctx)242085658deSDaniel Fojt __archive_md5init(archive_md5_ctx *ctx)
2436b384f39SPeter Avalos {
244e95abc47Szrj   if ((*ctx = EVP_MD_CTX_new()) == NULL)
245e95abc47Szrj 	return (ARCHIVE_FAILED);
246*50f8aa9cSAntonio Huete Jimenez   if (!EVP_DigestInit(*ctx, EVP_md5()))
247*50f8aa9cSAntonio Huete Jimenez 	return (ARCHIVE_FAILED);
2486b384f39SPeter Avalos   return (ARCHIVE_OK);
2496b384f39SPeter Avalos }
2506b384f39SPeter Avalos 
2516b384f39SPeter Avalos static int
__archive_md5update(archive_md5_ctx * ctx,const void * indata,size_t insize)252085658deSDaniel Fojt __archive_md5update(archive_md5_ctx *ctx, const void *indata,
2536b384f39SPeter Avalos     size_t insize)
2546b384f39SPeter Avalos {
255e95abc47Szrj   EVP_DigestUpdate(*ctx, indata, insize);
2566b384f39SPeter Avalos   return (ARCHIVE_OK);
2576b384f39SPeter Avalos }
2586b384f39SPeter Avalos 
2596b384f39SPeter Avalos static int
__archive_md5final(archive_md5_ctx * ctx,void * md)260085658deSDaniel Fojt __archive_md5final(archive_md5_ctx *ctx, void *md)
2616b384f39SPeter Avalos {
2626b384f39SPeter Avalos   /* HACK: archive_write_set_format_xar.c is finalizing empty contexts, so
2636b384f39SPeter Avalos    * this is meant to cope with that. Real fix is probably to fix
2646b384f39SPeter Avalos    * archive_write_set_format_xar.c
2656b384f39SPeter Avalos    */
266e95abc47Szrj   if (*ctx) {
267e95abc47Szrj     EVP_DigestFinal(*ctx, md, NULL);
268e95abc47Szrj     EVP_MD_CTX_free(*ctx);
269e95abc47Szrj     *ctx = NULL;
270e95abc47Szrj   }
2716b384f39SPeter Avalos   return (ARCHIVE_OK);
2726b384f39SPeter Avalos }
2736b384f39SPeter Avalos 
2746b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_MD5_WIN)
2756b384f39SPeter Avalos 
2766b384f39SPeter Avalos static int
__archive_md5init(archive_md5_ctx * ctx)277085658deSDaniel Fojt __archive_md5init(archive_md5_ctx *ctx)
2786b384f39SPeter Avalos {
2796b384f39SPeter Avalos   return (win_crypto_init(ctx, CALG_MD5));
2806b384f39SPeter Avalos }
2816b384f39SPeter Avalos 
2826b384f39SPeter Avalos static int
__archive_md5update(archive_md5_ctx * ctx,const void * indata,size_t insize)283085658deSDaniel Fojt __archive_md5update(archive_md5_ctx *ctx, const void *indata,
2846b384f39SPeter Avalos     size_t insize)
2856b384f39SPeter Avalos {
2866b384f39SPeter Avalos   return (win_crypto_Update(ctx, indata, insize));
2876b384f39SPeter Avalos }
2886b384f39SPeter Avalos 
2896b384f39SPeter Avalos static int
__archive_md5final(archive_md5_ctx * ctx,void * md)290085658deSDaniel Fojt __archive_md5final(archive_md5_ctx *ctx, void *md)
2916b384f39SPeter Avalos {
2926b384f39SPeter Avalos   return (win_crypto_Final(md, 16, ctx));
2936b384f39SPeter Avalos }
2946b384f39SPeter Avalos 
2956b384f39SPeter Avalos #else
2966b384f39SPeter Avalos 
2976b384f39SPeter Avalos static int
__archive_md5init(archive_md5_ctx * ctx)298085658deSDaniel Fojt __archive_md5init(archive_md5_ctx *ctx)
2996b384f39SPeter Avalos {
3006b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
3016b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
3026b384f39SPeter Avalos }
3036b384f39SPeter Avalos 
3046b384f39SPeter Avalos static int
__archive_md5update(archive_md5_ctx * ctx,const void * indata,size_t insize)305085658deSDaniel Fojt __archive_md5update(archive_md5_ctx *ctx, const void *indata,
3066b384f39SPeter Avalos     size_t insize)
3076b384f39SPeter Avalos {
3086b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
3096b384f39SPeter Avalos 	(void)indata; /* UNUSED */
3106b384f39SPeter Avalos 	(void)insize; /* UNUSED */
3116b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
3126b384f39SPeter Avalos }
3136b384f39SPeter Avalos 
3146b384f39SPeter Avalos static int
__archive_md5final(archive_md5_ctx * ctx,void * md)315085658deSDaniel Fojt __archive_md5final(archive_md5_ctx *ctx, void *md)
3166b384f39SPeter Avalos {
3176b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
3186b384f39SPeter Avalos 	(void)md; /* UNUSED */
3196b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
3206b384f39SPeter Avalos }
3216b384f39SPeter Avalos 
3226b384f39SPeter Avalos #endif
3236b384f39SPeter Avalos 
3246b384f39SPeter Avalos /* RIPEMD160 implementations */
3256b384f39SPeter Avalos #if defined(ARCHIVE_CRYPTO_RMD160_LIBC)
3266b384f39SPeter Avalos 
3276b384f39SPeter Avalos static int
__archive_ripemd160init(archive_rmd160_ctx * ctx)328085658deSDaniel Fojt __archive_ripemd160init(archive_rmd160_ctx *ctx)
3296b384f39SPeter Avalos {
3306b384f39SPeter Avalos   RMD160Init(ctx);
3316b384f39SPeter Avalos   return (ARCHIVE_OK);
3326b384f39SPeter Avalos }
3336b384f39SPeter Avalos 
3346b384f39SPeter Avalos static int
__archive_ripemd160update(archive_rmd160_ctx * ctx,const void * indata,size_t insize)335085658deSDaniel Fojt __archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
3366b384f39SPeter Avalos     size_t insize)
3376b384f39SPeter Avalos {
3386b384f39SPeter Avalos   RMD160Update(ctx, indata, insize);
3396b384f39SPeter Avalos   return (ARCHIVE_OK);
3406b384f39SPeter Avalos }
3416b384f39SPeter Avalos 
3426b384f39SPeter Avalos static int
__archive_ripemd160final(archive_rmd160_ctx * ctx,void * md)343085658deSDaniel Fojt __archive_ripemd160final(archive_rmd160_ctx *ctx, void *md)
3446b384f39SPeter Avalos {
3456b384f39SPeter Avalos   RMD160Final(md, ctx);
3466b384f39SPeter Avalos   return (ARCHIVE_OK);
3476b384f39SPeter Avalos }
3486b384f39SPeter Avalos 
3496b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD)
3506b384f39SPeter Avalos 
3516b384f39SPeter Avalos static int
__archive_ripemd160init(archive_rmd160_ctx * ctx)352085658deSDaniel Fojt __archive_ripemd160init(archive_rmd160_ctx *ctx)
3536b384f39SPeter Avalos {
3546b384f39SPeter Avalos   RIPEMD160_Init(ctx);
3556b384f39SPeter Avalos   return (ARCHIVE_OK);
3566b384f39SPeter Avalos }
3576b384f39SPeter Avalos 
3586b384f39SPeter Avalos static int
__archive_ripemd160update(archive_rmd160_ctx * ctx,const void * indata,size_t insize)359085658deSDaniel Fojt __archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
3606b384f39SPeter Avalos     size_t insize)
3616b384f39SPeter Avalos {
3626b384f39SPeter Avalos   RIPEMD160_Update(ctx, indata, insize);
3636b384f39SPeter Avalos   return (ARCHIVE_OK);
3646b384f39SPeter Avalos }
3656b384f39SPeter Avalos 
3666b384f39SPeter Avalos static int
__archive_ripemd160final(archive_rmd160_ctx * ctx,void * md)367085658deSDaniel Fojt __archive_ripemd160final(archive_rmd160_ctx *ctx, void *md)
3686b384f39SPeter Avalos {
3696b384f39SPeter Avalos   RIPEMD160_Final(md, ctx);
3706b384f39SPeter Avalos   return (ARCHIVE_OK);
3716b384f39SPeter Avalos }
3726b384f39SPeter Avalos 
373085658deSDaniel Fojt #elif defined(ARCHIVE_CRYPTO_RMD160_MBEDTLS)
374085658deSDaniel Fojt 
375085658deSDaniel Fojt static int
__archive_ripemd160init(archive_rmd160_ctx * ctx)376085658deSDaniel Fojt __archive_ripemd160init(archive_rmd160_ctx *ctx)
377085658deSDaniel Fojt {
378085658deSDaniel Fojt   mbedtls_ripemd160_init(ctx);
379085658deSDaniel Fojt   if (mbedtls_ripemd160_starts_ret(ctx) == 0)
380085658deSDaniel Fojt     return (ARCHIVE_OK);
381085658deSDaniel Fojt   else
382085658deSDaniel Fojt     return (ARCHIVE_FATAL);
383085658deSDaniel Fojt }
384085658deSDaniel Fojt 
385085658deSDaniel Fojt static int
__archive_ripemd160update(archive_rmd160_ctx * ctx,const void * indata,size_t insize)386085658deSDaniel Fojt __archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
387085658deSDaniel Fojt     size_t insize)
388085658deSDaniel Fojt {
389085658deSDaniel Fojt   if (mbedtls_ripemd160_update_ret(ctx, indata, insize) == 0)
390085658deSDaniel Fojt     return (ARCHIVE_OK);
391085658deSDaniel Fojt   else
392085658deSDaniel Fojt     return (ARCHIVE_FATAL);
393085658deSDaniel Fojt }
394085658deSDaniel Fojt 
395085658deSDaniel Fojt static int
__archive_ripemd160final(archive_rmd160_ctx * ctx,void * md)396085658deSDaniel Fojt __archive_ripemd160final(archive_rmd160_ctx *ctx, void *md)
397085658deSDaniel Fojt {
398085658deSDaniel Fojt   if (mbedtls_ripemd160_finish_ret(ctx, md) == 0) {
399085658deSDaniel Fojt     mbedtls_ripemd160_free(ctx);
400085658deSDaniel Fojt     return (ARCHIVE_OK);
401085658deSDaniel Fojt   } else {
402085658deSDaniel Fojt     mbedtls_ripemd160_free(ctx);
403085658deSDaniel Fojt     return (ARCHIVE_FATAL);
404085658deSDaniel Fojt   }
405085658deSDaniel Fojt }
406085658deSDaniel Fojt 
4076b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE)
4086b384f39SPeter Avalos 
4096b384f39SPeter Avalos static int
__archive_ripemd160init(archive_rmd160_ctx * ctx)410085658deSDaniel Fojt __archive_ripemd160init(archive_rmd160_ctx *ctx)
4116b384f39SPeter Avalos {
4126b384f39SPeter Avalos   ripemd160_init(ctx);
4136b384f39SPeter Avalos   return (ARCHIVE_OK);
4146b384f39SPeter Avalos }
4156b384f39SPeter Avalos 
4166b384f39SPeter Avalos static int
__archive_ripemd160update(archive_rmd160_ctx * ctx,const void * indata,size_t insize)417085658deSDaniel Fojt __archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
4186b384f39SPeter Avalos     size_t insize)
4196b384f39SPeter Avalos {
4206b384f39SPeter Avalos   ripemd160_update(ctx, insize, indata);
4216b384f39SPeter Avalos   return (ARCHIVE_OK);
4226b384f39SPeter Avalos }
4236b384f39SPeter Avalos 
4246b384f39SPeter Avalos static int
__archive_ripemd160final(archive_rmd160_ctx * ctx,void * md)425085658deSDaniel Fojt __archive_ripemd160final(archive_rmd160_ctx *ctx, void *md)
4266b384f39SPeter Avalos {
4276b384f39SPeter Avalos   ripemd160_digest(ctx, RIPEMD160_DIGEST_SIZE, md);
4286b384f39SPeter Avalos   return (ARCHIVE_OK);
4296b384f39SPeter Avalos }
4306b384f39SPeter Avalos 
4316b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL)
4326b384f39SPeter Avalos 
4336b384f39SPeter Avalos static int
__archive_ripemd160init(archive_rmd160_ctx * ctx)434085658deSDaniel Fojt __archive_ripemd160init(archive_rmd160_ctx *ctx)
4356b384f39SPeter Avalos {
436e95abc47Szrj   if ((*ctx = EVP_MD_CTX_new()) == NULL)
437e95abc47Szrj 	return (ARCHIVE_FAILED);
438*50f8aa9cSAntonio Huete Jimenez   if (!EVP_DigestInit(*ctx, EVP_ripemd160()))
439*50f8aa9cSAntonio Huete Jimenez 	return (ARCHIVE_FAILED);
4406b384f39SPeter Avalos   return (ARCHIVE_OK);
4416b384f39SPeter Avalos }
4426b384f39SPeter Avalos 
4436b384f39SPeter Avalos static int
__archive_ripemd160update(archive_rmd160_ctx * ctx,const void * indata,size_t insize)444085658deSDaniel Fojt __archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
4456b384f39SPeter Avalos     size_t insize)
4466b384f39SPeter Avalos {
447e95abc47Szrj   EVP_DigestUpdate(*ctx, indata, insize);
4486b384f39SPeter Avalos   return (ARCHIVE_OK);
4496b384f39SPeter Avalos }
4506b384f39SPeter Avalos 
4516b384f39SPeter Avalos static int
__archive_ripemd160final(archive_rmd160_ctx * ctx,void * md)452085658deSDaniel Fojt __archive_ripemd160final(archive_rmd160_ctx *ctx, void *md)
4536b384f39SPeter Avalos {
454e95abc47Szrj   if (*ctx) {
455e95abc47Szrj     EVP_DigestFinal(*ctx, md, NULL);
456e95abc47Szrj     EVP_MD_CTX_free(*ctx);
457e95abc47Szrj     *ctx = NULL;
458e95abc47Szrj   }
4596b384f39SPeter Avalos   return (ARCHIVE_OK);
4606b384f39SPeter Avalos }
4616b384f39SPeter Avalos 
4626b384f39SPeter Avalos #else
4636b384f39SPeter Avalos 
4646b384f39SPeter Avalos static int
__archive_ripemd160init(archive_rmd160_ctx * ctx)465085658deSDaniel Fojt __archive_ripemd160init(archive_rmd160_ctx *ctx)
4666b384f39SPeter Avalos {
4676b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
4686b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
4696b384f39SPeter Avalos }
4706b384f39SPeter Avalos 
4716b384f39SPeter Avalos static int
__archive_ripemd160update(archive_rmd160_ctx * ctx,const void * indata,size_t insize)472085658deSDaniel Fojt __archive_ripemd160update(archive_rmd160_ctx *ctx, const void *indata,
4736b384f39SPeter Avalos     size_t insize)
4746b384f39SPeter Avalos {
4756b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
4766b384f39SPeter Avalos 	(void)indata; /* UNUSED */
4776b384f39SPeter Avalos 	(void)insize; /* UNUSED */
4786b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
4796b384f39SPeter Avalos }
4806b384f39SPeter Avalos 
4816b384f39SPeter Avalos static int
__archive_ripemd160final(archive_rmd160_ctx * ctx,void * md)482085658deSDaniel Fojt __archive_ripemd160final(archive_rmd160_ctx *ctx, void *md)
4836b384f39SPeter Avalos {
4846b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
4856b384f39SPeter Avalos 	(void)md; /* UNUSED */
4866b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
4876b384f39SPeter Avalos }
4886b384f39SPeter Avalos 
4896b384f39SPeter Avalos #endif
4906b384f39SPeter Avalos 
4916b384f39SPeter Avalos /* SHA1 implementations */
4926b384f39SPeter Avalos #if defined(ARCHIVE_CRYPTO_SHA1_LIBC)
4936b384f39SPeter Avalos 
4946b384f39SPeter Avalos static int
__archive_sha1init(archive_sha1_ctx * ctx)495085658deSDaniel Fojt __archive_sha1init(archive_sha1_ctx *ctx)
4966b384f39SPeter Avalos {
4976b384f39SPeter Avalos   SHA1Init(ctx);
4986b384f39SPeter Avalos   return (ARCHIVE_OK);
4996b384f39SPeter Avalos }
5006b384f39SPeter Avalos 
5016b384f39SPeter Avalos static int
__archive_sha1update(archive_sha1_ctx * ctx,const void * indata,size_t insize)502085658deSDaniel Fojt __archive_sha1update(archive_sha1_ctx *ctx, const void *indata,
5036b384f39SPeter Avalos     size_t insize)
5046b384f39SPeter Avalos {
5056b384f39SPeter Avalos   SHA1Update(ctx, indata, insize);
5066b384f39SPeter Avalos   return (ARCHIVE_OK);
5076b384f39SPeter Avalos }
5086b384f39SPeter Avalos 
5096b384f39SPeter Avalos static int
__archive_sha1final(archive_sha1_ctx * ctx,void * md)510085658deSDaniel Fojt __archive_sha1final(archive_sha1_ctx *ctx, void *md)
5116b384f39SPeter Avalos {
5126b384f39SPeter Avalos   SHA1Final(md, ctx);
5136b384f39SPeter Avalos   return (ARCHIVE_OK);
5146b384f39SPeter Avalos }
5156b384f39SPeter Avalos 
5166b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA1_LIBMD)
5176b384f39SPeter Avalos 
5186b384f39SPeter Avalos static int
__archive_sha1init(archive_sha1_ctx * ctx)519085658deSDaniel Fojt __archive_sha1init(archive_sha1_ctx *ctx)
5206b384f39SPeter Avalos {
5216b384f39SPeter Avalos   SHA1_Init(ctx);
5226b384f39SPeter Avalos   return (ARCHIVE_OK);
5236b384f39SPeter Avalos }
5246b384f39SPeter Avalos 
5256b384f39SPeter Avalos static int
__archive_sha1update(archive_sha1_ctx * ctx,const void * indata,size_t insize)526085658deSDaniel Fojt __archive_sha1update(archive_sha1_ctx *ctx, const void *indata,
5276b384f39SPeter Avalos     size_t insize)
5286b384f39SPeter Avalos {
5296b384f39SPeter Avalos   SHA1_Update(ctx, indata, insize);
5306b384f39SPeter Avalos   return (ARCHIVE_OK);
5316b384f39SPeter Avalos }
5326b384f39SPeter Avalos 
5336b384f39SPeter Avalos static int
__archive_sha1final(archive_sha1_ctx * ctx,void * md)534085658deSDaniel Fojt __archive_sha1final(archive_sha1_ctx *ctx, void *md)
5356b384f39SPeter Avalos {
5366b384f39SPeter Avalos   SHA1_Final(md, ctx);
5376b384f39SPeter Avalos   return (ARCHIVE_OK);
5386b384f39SPeter Avalos }
5396b384f39SPeter Avalos 
5406b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM)
5416b384f39SPeter Avalos 
5426b384f39SPeter Avalos static int
__archive_sha1init(archive_sha1_ctx * ctx)543085658deSDaniel Fojt __archive_sha1init(archive_sha1_ctx *ctx)
5446b384f39SPeter Avalos {
5456b384f39SPeter Avalos   CC_SHA1_Init(ctx);
5466b384f39SPeter Avalos   return (ARCHIVE_OK);
5476b384f39SPeter Avalos }
5486b384f39SPeter Avalos 
5496b384f39SPeter Avalos static int
__archive_sha1update(archive_sha1_ctx * ctx,const void * indata,size_t insize)550085658deSDaniel Fojt __archive_sha1update(archive_sha1_ctx *ctx, const void *indata,
5516b384f39SPeter Avalos     size_t insize)
5526b384f39SPeter Avalos {
5536b384f39SPeter Avalos   CC_SHA1_Update(ctx, indata, insize);
5546b384f39SPeter Avalos   return (ARCHIVE_OK);
5556b384f39SPeter Avalos }
5566b384f39SPeter Avalos 
5576b384f39SPeter Avalos static int
__archive_sha1final(archive_sha1_ctx * ctx,void * md)558085658deSDaniel Fojt __archive_sha1final(archive_sha1_ctx *ctx, void *md)
5596b384f39SPeter Avalos {
5606b384f39SPeter Avalos   CC_SHA1_Final(md, ctx);
5616b384f39SPeter Avalos   return (ARCHIVE_OK);
5626b384f39SPeter Avalos }
5636b384f39SPeter Avalos 
564085658deSDaniel Fojt #elif defined(ARCHIVE_CRYPTO_SHA1_MBEDTLS)
565085658deSDaniel Fojt 
566085658deSDaniel Fojt static int
__archive_sha1init(archive_sha1_ctx * ctx)567085658deSDaniel Fojt __archive_sha1init(archive_sha1_ctx *ctx)
568085658deSDaniel Fojt {
569085658deSDaniel Fojt   mbedtls_sha1_init(ctx);
570085658deSDaniel Fojt   if (mbedtls_sha1_starts_ret(ctx) == 0)
571085658deSDaniel Fojt     return (ARCHIVE_OK);
572085658deSDaniel Fojt   else
573085658deSDaniel Fojt     return (ARCHIVE_FATAL);
574085658deSDaniel Fojt }
575085658deSDaniel Fojt 
576085658deSDaniel Fojt static int
__archive_sha1update(archive_sha1_ctx * ctx,const void * indata,size_t insize)577085658deSDaniel Fojt __archive_sha1update(archive_sha1_ctx *ctx, const void *indata,
578085658deSDaniel Fojt     size_t insize)
579085658deSDaniel Fojt {
580085658deSDaniel Fojt   if (mbedtls_sha1_update_ret(ctx, indata, insize) == 0)
581085658deSDaniel Fojt     return (ARCHIVE_OK);
582085658deSDaniel Fojt   else
583085658deSDaniel Fojt     return (ARCHIVE_FATAL);
584085658deSDaniel Fojt }
585085658deSDaniel Fojt 
586085658deSDaniel Fojt static int
__archive_sha1final(archive_sha1_ctx * ctx,void * md)587085658deSDaniel Fojt __archive_sha1final(archive_sha1_ctx *ctx, void *md)
588085658deSDaniel Fojt {
589085658deSDaniel Fojt   if (mbedtls_sha1_finish_ret(ctx, md) == 0) {
590085658deSDaniel Fojt     mbedtls_sha1_free(ctx);
591085658deSDaniel Fojt     return (ARCHIVE_OK);
592085658deSDaniel Fojt   } else {
593085658deSDaniel Fojt     mbedtls_sha1_free(ctx);
594085658deSDaniel Fojt     return (ARCHIVE_FATAL);
595085658deSDaniel Fojt   }
596085658deSDaniel Fojt }
597085658deSDaniel Fojt 
5986b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE)
5996b384f39SPeter Avalos 
6006b384f39SPeter Avalos static int
__archive_sha1init(archive_sha1_ctx * ctx)601085658deSDaniel Fojt __archive_sha1init(archive_sha1_ctx *ctx)
6026b384f39SPeter Avalos {
6036b384f39SPeter Avalos   sha1_init(ctx);
6046b384f39SPeter Avalos   return (ARCHIVE_OK);
6056b384f39SPeter Avalos }
6066b384f39SPeter Avalos 
6076b384f39SPeter Avalos static int
__archive_sha1update(archive_sha1_ctx * ctx,const void * indata,size_t insize)608085658deSDaniel Fojt __archive_sha1update(archive_sha1_ctx *ctx, const void *indata,
6096b384f39SPeter Avalos     size_t insize)
6106b384f39SPeter Avalos {
6116b384f39SPeter Avalos   sha1_update(ctx, insize, indata);
6126b384f39SPeter Avalos   return (ARCHIVE_OK);
6136b384f39SPeter Avalos }
6146b384f39SPeter Avalos 
6156b384f39SPeter Avalos static int
__archive_sha1final(archive_sha1_ctx * ctx,void * md)616085658deSDaniel Fojt __archive_sha1final(archive_sha1_ctx *ctx, void *md)
6176b384f39SPeter Avalos {
6186b384f39SPeter Avalos   sha1_digest(ctx, SHA1_DIGEST_SIZE, md);
6196b384f39SPeter Avalos   return (ARCHIVE_OK);
6206b384f39SPeter Avalos }
6216b384f39SPeter Avalos 
6226b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL)
6236b384f39SPeter Avalos 
6246b384f39SPeter Avalos static int
__archive_sha1init(archive_sha1_ctx * ctx)625085658deSDaniel Fojt __archive_sha1init(archive_sha1_ctx *ctx)
6266b384f39SPeter Avalos {
627e95abc47Szrj   if ((*ctx = EVP_MD_CTX_new()) == NULL)
628e95abc47Szrj 	return (ARCHIVE_FAILED);
629*50f8aa9cSAntonio Huete Jimenez   if (!EVP_DigestInit(*ctx, EVP_sha1()))
630*50f8aa9cSAntonio Huete Jimenez 	return (ARCHIVE_FAILED);
6316b384f39SPeter Avalos   return (ARCHIVE_OK);
6326b384f39SPeter Avalos }
6336b384f39SPeter Avalos 
6346b384f39SPeter Avalos static int
__archive_sha1update(archive_sha1_ctx * ctx,const void * indata,size_t insize)635085658deSDaniel Fojt __archive_sha1update(archive_sha1_ctx *ctx, const void *indata,
6366b384f39SPeter Avalos     size_t insize)
6376b384f39SPeter Avalos {
638e95abc47Szrj   EVP_DigestUpdate(*ctx, indata, insize);
6396b384f39SPeter Avalos   return (ARCHIVE_OK);
6406b384f39SPeter Avalos }
6416b384f39SPeter Avalos 
6426b384f39SPeter Avalos static int
__archive_sha1final(archive_sha1_ctx * ctx,void * md)643085658deSDaniel Fojt __archive_sha1final(archive_sha1_ctx *ctx, void *md)
6446b384f39SPeter Avalos {
6456b384f39SPeter Avalos   /* HACK: archive_write_set_format_xar.c is finalizing empty contexts, so
6466b384f39SPeter Avalos    * this is meant to cope with that. Real fix is probably to fix
6476b384f39SPeter Avalos    * archive_write_set_format_xar.c
6486b384f39SPeter Avalos    */
649e95abc47Szrj   if (*ctx) {
650e95abc47Szrj     EVP_DigestFinal(*ctx, md, NULL);
651e95abc47Szrj     EVP_MD_CTX_free(*ctx);
652e95abc47Szrj     *ctx = NULL;
653e95abc47Szrj   }
6546b384f39SPeter Avalos   return (ARCHIVE_OK);
6556b384f39SPeter Avalos }
6566b384f39SPeter Avalos 
6576b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA1_WIN)
6586b384f39SPeter Avalos 
6596b384f39SPeter Avalos static int
__archive_sha1init(archive_sha1_ctx * ctx)660085658deSDaniel Fojt __archive_sha1init(archive_sha1_ctx *ctx)
6616b384f39SPeter Avalos {
6626b384f39SPeter Avalos   return (win_crypto_init(ctx, CALG_SHA1));
6636b384f39SPeter Avalos }
6646b384f39SPeter Avalos 
6656b384f39SPeter Avalos static int
__archive_sha1update(archive_sha1_ctx * ctx,const void * indata,size_t insize)666085658deSDaniel Fojt __archive_sha1update(archive_sha1_ctx *ctx, const void *indata,
6676b384f39SPeter Avalos     size_t insize)
6686b384f39SPeter Avalos {
6696b384f39SPeter Avalos   return (win_crypto_Update(ctx, indata, insize));
6706b384f39SPeter Avalos }
6716b384f39SPeter Avalos 
6726b384f39SPeter Avalos static int
__archive_sha1final(archive_sha1_ctx * ctx,void * md)673085658deSDaniel Fojt __archive_sha1final(archive_sha1_ctx *ctx, void *md)
6746b384f39SPeter Avalos {
6756b384f39SPeter Avalos   return (win_crypto_Final(md, 20, ctx));
6766b384f39SPeter Avalos }
6776b384f39SPeter Avalos 
6786b384f39SPeter Avalos #else
6796b384f39SPeter Avalos 
6806b384f39SPeter Avalos static int
__archive_sha1init(archive_sha1_ctx * ctx)681085658deSDaniel Fojt __archive_sha1init(archive_sha1_ctx *ctx)
6826b384f39SPeter Avalos {
6836b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
6846b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
6856b384f39SPeter Avalos }
6866b384f39SPeter Avalos 
6876b384f39SPeter Avalos static int
__archive_sha1update(archive_sha1_ctx * ctx,const void * indata,size_t insize)688085658deSDaniel Fojt __archive_sha1update(archive_sha1_ctx *ctx, const void *indata,
6896b384f39SPeter Avalos     size_t insize)
6906b384f39SPeter Avalos {
6916b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
6926b384f39SPeter Avalos 	(void)indata; /* UNUSED */
6936b384f39SPeter Avalos 	(void)insize; /* UNUSED */
6946b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
6956b384f39SPeter Avalos }
6966b384f39SPeter Avalos 
6976b384f39SPeter Avalos static int
__archive_sha1final(archive_sha1_ctx * ctx,void * md)698085658deSDaniel Fojt __archive_sha1final(archive_sha1_ctx *ctx, void *md)
6996b384f39SPeter Avalos {
7006b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
7016b384f39SPeter Avalos 	(void)md; /* UNUSED */
7026b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
7036b384f39SPeter Avalos }
7046b384f39SPeter Avalos 
7056b384f39SPeter Avalos #endif
7066b384f39SPeter Avalos 
7076b384f39SPeter Avalos /* SHA256 implementations */
7086b384f39SPeter Avalos #if defined(ARCHIVE_CRYPTO_SHA256_LIBC)
7096b384f39SPeter Avalos 
7106b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)711085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
7126b384f39SPeter Avalos {
7136b384f39SPeter Avalos   SHA256_Init(ctx);
7146b384f39SPeter Avalos   return (ARCHIVE_OK);
7156b384f39SPeter Avalos }
7166b384f39SPeter Avalos 
7176b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)718085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
7196b384f39SPeter Avalos     size_t insize)
7206b384f39SPeter Avalos {
7216b384f39SPeter Avalos   SHA256_Update(ctx, indata, insize);
7226b384f39SPeter Avalos   return (ARCHIVE_OK);
7236b384f39SPeter Avalos }
7246b384f39SPeter Avalos 
7256b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)726085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
7276b384f39SPeter Avalos {
7286b384f39SPeter Avalos   SHA256_Final(md, ctx);
7296b384f39SPeter Avalos   return (ARCHIVE_OK);
7306b384f39SPeter Avalos }
7316b384f39SPeter Avalos 
7326b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA256_LIBC2)
7336b384f39SPeter Avalos 
7346b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)735085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
7366b384f39SPeter Avalos {
7376b384f39SPeter Avalos   SHA256Init(ctx);
7386b384f39SPeter Avalos   return (ARCHIVE_OK);
7396b384f39SPeter Avalos }
7406b384f39SPeter Avalos 
7416b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)742085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
7436b384f39SPeter Avalos     size_t insize)
7446b384f39SPeter Avalos {
7456b384f39SPeter Avalos   SHA256Update(ctx, indata, insize);
7466b384f39SPeter Avalos   return (ARCHIVE_OK);
7476b384f39SPeter Avalos }
7486b384f39SPeter Avalos 
7496b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)750085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
7516b384f39SPeter Avalos {
7526b384f39SPeter Avalos   SHA256Final(md, ctx);
7536b384f39SPeter Avalos   return (ARCHIVE_OK);
7546b384f39SPeter Avalos }
7556b384f39SPeter Avalos 
7566b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA256_LIBC3)
7576b384f39SPeter Avalos 
7586b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)759085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
7606b384f39SPeter Avalos {
7616b384f39SPeter Avalos   SHA256Init(ctx);
7626b384f39SPeter Avalos   return (ARCHIVE_OK);
7636b384f39SPeter Avalos }
7646b384f39SPeter Avalos 
7656b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)766085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
7676b384f39SPeter Avalos     size_t insize)
7686b384f39SPeter Avalos {
7696b384f39SPeter Avalos   SHA256Update(ctx, indata, insize);
7706b384f39SPeter Avalos   return (ARCHIVE_OK);
7716b384f39SPeter Avalos }
7726b384f39SPeter Avalos 
7736b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)774085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
7756b384f39SPeter Avalos {
7766b384f39SPeter Avalos   SHA256Final(md, ctx);
7776b384f39SPeter Avalos   return (ARCHIVE_OK);
7786b384f39SPeter Avalos }
7796b384f39SPeter Avalos 
7806b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA256_LIBMD)
7816b384f39SPeter Avalos 
7826b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)783085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
7846b384f39SPeter Avalos {
7856b384f39SPeter Avalos   SHA256_Init(ctx);
7866b384f39SPeter Avalos   return (ARCHIVE_OK);
7876b384f39SPeter Avalos }
7886b384f39SPeter Avalos 
7896b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)790085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
7916b384f39SPeter Avalos     size_t insize)
7926b384f39SPeter Avalos {
7936b384f39SPeter Avalos   SHA256_Update(ctx, indata, insize);
7946b384f39SPeter Avalos   return (ARCHIVE_OK);
7956b384f39SPeter Avalos }
7966b384f39SPeter Avalos 
7976b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)798085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
7996b384f39SPeter Avalos {
8006b384f39SPeter Avalos   SHA256_Final(md, ctx);
8016b384f39SPeter Avalos   return (ARCHIVE_OK);
8026b384f39SPeter Avalos }
8036b384f39SPeter Avalos 
8046b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM)
8056b384f39SPeter Avalos 
8066b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)807085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
8086b384f39SPeter Avalos {
8096b384f39SPeter Avalos   CC_SHA256_Init(ctx);
8106b384f39SPeter Avalos   return (ARCHIVE_OK);
8116b384f39SPeter Avalos }
8126b384f39SPeter Avalos 
8136b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)814085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
8156b384f39SPeter Avalos     size_t insize)
8166b384f39SPeter Avalos {
8176b384f39SPeter Avalos   CC_SHA256_Update(ctx, indata, insize);
8186b384f39SPeter Avalos   return (ARCHIVE_OK);
8196b384f39SPeter Avalos }
8206b384f39SPeter Avalos 
8216b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)822085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
8236b384f39SPeter Avalos {
8246b384f39SPeter Avalos   CC_SHA256_Final(md, ctx);
8256b384f39SPeter Avalos   return (ARCHIVE_OK);
8266b384f39SPeter Avalos }
8276b384f39SPeter Avalos 
828085658deSDaniel Fojt #elif defined(ARCHIVE_CRYPTO_SHA256_MBEDTLS)
829085658deSDaniel Fojt 
830085658deSDaniel Fojt static int
__archive_sha256init(archive_sha256_ctx * ctx)831085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
832085658deSDaniel Fojt {
833085658deSDaniel Fojt   mbedtls_sha256_init(ctx);
834085658deSDaniel Fojt   if (mbedtls_sha256_starts_ret(ctx, 0) == 0)
835085658deSDaniel Fojt     return (ARCHIVE_OK);
836085658deSDaniel Fojt   else
837085658deSDaniel Fojt     return (ARCHIVE_FATAL);
838085658deSDaniel Fojt }
839085658deSDaniel Fojt 
840085658deSDaniel Fojt static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)841085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
842085658deSDaniel Fojt     size_t insize)
843085658deSDaniel Fojt {
844085658deSDaniel Fojt   if (mbedtls_sha256_update_ret(ctx, indata, insize) == 0)
845085658deSDaniel Fojt     return (ARCHIVE_OK);
846085658deSDaniel Fojt   else
847085658deSDaniel Fojt     return (ARCHIVE_FATAL);
848085658deSDaniel Fojt }
849085658deSDaniel Fojt 
850085658deSDaniel Fojt static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)851085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
852085658deSDaniel Fojt {
853085658deSDaniel Fojt   if (mbedtls_sha256_finish_ret(ctx, md) == 0) {
854085658deSDaniel Fojt     mbedtls_sha256_free(ctx);
855085658deSDaniel Fojt     return (ARCHIVE_OK);
856085658deSDaniel Fojt   } else {
857085658deSDaniel Fojt     mbedtls_sha256_free(ctx);
858085658deSDaniel Fojt     return (ARCHIVE_FATAL);
859085658deSDaniel Fojt   }
860085658deSDaniel Fojt }
861085658deSDaniel Fojt 
8626b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE)
8636b384f39SPeter Avalos 
8646b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)865085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
8666b384f39SPeter Avalos {
8676b384f39SPeter Avalos   sha256_init(ctx);
8686b384f39SPeter Avalos   return (ARCHIVE_OK);
8696b384f39SPeter Avalos }
8706b384f39SPeter Avalos 
8716b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)872085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
8736b384f39SPeter Avalos     size_t insize)
8746b384f39SPeter Avalos {
8756b384f39SPeter Avalos   sha256_update(ctx, insize, indata);
8766b384f39SPeter Avalos   return (ARCHIVE_OK);
8776b384f39SPeter Avalos }
8786b384f39SPeter Avalos 
8796b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)880085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
8816b384f39SPeter Avalos {
8826b384f39SPeter Avalos   sha256_digest(ctx, SHA256_DIGEST_SIZE, md);
8836b384f39SPeter Avalos   return (ARCHIVE_OK);
8846b384f39SPeter Avalos }
8856b384f39SPeter Avalos 
8866b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL)
8876b384f39SPeter Avalos 
8886b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)889085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
8906b384f39SPeter Avalos {
891e95abc47Szrj   if ((*ctx = EVP_MD_CTX_new()) == NULL)
892e95abc47Szrj 	return (ARCHIVE_FAILED);
893*50f8aa9cSAntonio Huete Jimenez   if (!EVP_DigestInit(*ctx, EVP_sha256()))
894*50f8aa9cSAntonio Huete Jimenez 	return (ARCHIVE_FAILED);
8956b384f39SPeter Avalos   return (ARCHIVE_OK);
8966b384f39SPeter Avalos }
8976b384f39SPeter Avalos 
8986b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)899085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
9006b384f39SPeter Avalos     size_t insize)
9016b384f39SPeter Avalos {
902e95abc47Szrj   EVP_DigestUpdate(*ctx, indata, insize);
9036b384f39SPeter Avalos   return (ARCHIVE_OK);
9046b384f39SPeter Avalos }
9056b384f39SPeter Avalos 
9066b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)907085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
9086b384f39SPeter Avalos {
909e95abc47Szrj   if (*ctx) {
910e95abc47Szrj     EVP_DigestFinal(*ctx, md, NULL);
911e95abc47Szrj     EVP_MD_CTX_free(*ctx);
912e95abc47Szrj     *ctx = NULL;
913e95abc47Szrj   }
9146b384f39SPeter Avalos   return (ARCHIVE_OK);
9156b384f39SPeter Avalos }
9166b384f39SPeter Avalos 
9176b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA256_WIN)
9186b384f39SPeter Avalos 
9196b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)920085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
9216b384f39SPeter Avalos {
9226b384f39SPeter Avalos   return (win_crypto_init(ctx, CALG_SHA_256));
9236b384f39SPeter Avalos }
9246b384f39SPeter Avalos 
9256b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)926085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
9276b384f39SPeter Avalos     size_t insize)
9286b384f39SPeter Avalos {
9296b384f39SPeter Avalos   return (win_crypto_Update(ctx, indata, insize));
9306b384f39SPeter Avalos }
9316b384f39SPeter Avalos 
9326b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)933085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
9346b384f39SPeter Avalos {
9356b384f39SPeter Avalos   return (win_crypto_Final(md, 32, ctx));
9366b384f39SPeter Avalos }
9376b384f39SPeter Avalos 
9386b384f39SPeter Avalos #else
9396b384f39SPeter Avalos 
9406b384f39SPeter Avalos static int
__archive_sha256init(archive_sha256_ctx * ctx)941085658deSDaniel Fojt __archive_sha256init(archive_sha256_ctx *ctx)
9426b384f39SPeter Avalos {
9436b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
9446b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
9456b384f39SPeter Avalos }
9466b384f39SPeter Avalos 
9476b384f39SPeter Avalos static int
__archive_sha256update(archive_sha256_ctx * ctx,const void * indata,size_t insize)948085658deSDaniel Fojt __archive_sha256update(archive_sha256_ctx *ctx, const void *indata,
9496b384f39SPeter Avalos     size_t insize)
9506b384f39SPeter Avalos {
9516b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
9526b384f39SPeter Avalos 	(void)indata; /* UNUSED */
9536b384f39SPeter Avalos 	(void)insize; /* UNUSED */
9546b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
9556b384f39SPeter Avalos }
9566b384f39SPeter Avalos 
9576b384f39SPeter Avalos static int
__archive_sha256final(archive_sha256_ctx * ctx,void * md)958085658deSDaniel Fojt __archive_sha256final(archive_sha256_ctx *ctx, void *md)
9596b384f39SPeter Avalos {
9606b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
9616b384f39SPeter Avalos 	(void)md; /* UNUSED */
9626b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
9636b384f39SPeter Avalos }
9646b384f39SPeter Avalos 
9656b384f39SPeter Avalos #endif
9666b384f39SPeter Avalos 
9676b384f39SPeter Avalos /* SHA384 implementations */
9686b384f39SPeter Avalos #if defined(ARCHIVE_CRYPTO_SHA384_LIBC)
9696b384f39SPeter Avalos 
9706b384f39SPeter Avalos static int
__archive_sha384init(archive_sha384_ctx * ctx)971085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
9726b384f39SPeter Avalos {
9736b384f39SPeter Avalos   SHA384_Init(ctx);
9746b384f39SPeter Avalos   return (ARCHIVE_OK);
9756b384f39SPeter Avalos }
9766b384f39SPeter Avalos 
9776b384f39SPeter Avalos static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)978085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
9796b384f39SPeter Avalos     size_t insize)
9806b384f39SPeter Avalos {
9816b384f39SPeter Avalos   SHA384_Update(ctx, indata, insize);
9826b384f39SPeter Avalos   return (ARCHIVE_OK);
9836b384f39SPeter Avalos }
9846b384f39SPeter Avalos 
9856b384f39SPeter Avalos static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)986085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
9876b384f39SPeter Avalos {
9886b384f39SPeter Avalos   SHA384_Final(md, ctx);
9896b384f39SPeter Avalos   return (ARCHIVE_OK);
9906b384f39SPeter Avalos }
9916b384f39SPeter Avalos 
9926b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA384_LIBC2)
9936b384f39SPeter Avalos 
9946b384f39SPeter Avalos static int
__archive_sha384init(archive_sha384_ctx * ctx)995085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
9966b384f39SPeter Avalos {
9976b384f39SPeter Avalos   SHA384Init(ctx);
9986b384f39SPeter Avalos   return (ARCHIVE_OK);
9996b384f39SPeter Avalos }
10006b384f39SPeter Avalos 
10016b384f39SPeter Avalos static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)1002085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
10036b384f39SPeter Avalos     size_t insize)
10046b384f39SPeter Avalos {
10056b384f39SPeter Avalos   SHA384Update(ctx, indata, insize);
10066b384f39SPeter Avalos   return (ARCHIVE_OK);
10076b384f39SPeter Avalos }
10086b384f39SPeter Avalos 
10096b384f39SPeter Avalos static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)1010085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
10116b384f39SPeter Avalos {
10126b384f39SPeter Avalos   SHA384Final(md, ctx);
10136b384f39SPeter Avalos   return (ARCHIVE_OK);
10146b384f39SPeter Avalos }
10156b384f39SPeter Avalos 
10166b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA384_LIBC3)
10176b384f39SPeter Avalos 
10186b384f39SPeter Avalos static int
__archive_sha384init(archive_sha384_ctx * ctx)1019085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
10206b384f39SPeter Avalos {
10216b384f39SPeter Avalos   SHA384Init(ctx);
10226b384f39SPeter Avalos   return (ARCHIVE_OK);
10236b384f39SPeter Avalos }
10246b384f39SPeter Avalos 
10256b384f39SPeter Avalos static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)1026085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
10276b384f39SPeter Avalos     size_t insize)
10286b384f39SPeter Avalos {
10296b384f39SPeter Avalos   SHA384Update(ctx, indata, insize);
10306b384f39SPeter Avalos   return (ARCHIVE_OK);
10316b384f39SPeter Avalos }
10326b384f39SPeter Avalos 
10336b384f39SPeter Avalos static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)1034085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
10356b384f39SPeter Avalos {
10366b384f39SPeter Avalos   SHA384Final(md, ctx);
10376b384f39SPeter Avalos   return (ARCHIVE_OK);
10386b384f39SPeter Avalos }
10396b384f39SPeter Avalos 
10406b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM)
10416b384f39SPeter Avalos 
10426b384f39SPeter Avalos static int
__archive_sha384init(archive_sha384_ctx * ctx)1043085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
10446b384f39SPeter Avalos {
10456b384f39SPeter Avalos   CC_SHA384_Init(ctx);
10466b384f39SPeter Avalos   return (ARCHIVE_OK);
10476b384f39SPeter Avalos }
10486b384f39SPeter Avalos 
10496b384f39SPeter Avalos static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)1050085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
10516b384f39SPeter Avalos     size_t insize)
10526b384f39SPeter Avalos {
10536b384f39SPeter Avalos   CC_SHA384_Update(ctx, indata, insize);
10546b384f39SPeter Avalos   return (ARCHIVE_OK);
10556b384f39SPeter Avalos }
10566b384f39SPeter Avalos 
10576b384f39SPeter Avalos static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)1058085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
10596b384f39SPeter Avalos {
10606b384f39SPeter Avalos   CC_SHA384_Final(md, ctx);
10616b384f39SPeter Avalos   return (ARCHIVE_OK);
10626b384f39SPeter Avalos }
10636b384f39SPeter Avalos 
1064085658deSDaniel Fojt #elif defined(ARCHIVE_CRYPTO_SHA384_MBEDTLS)
1065085658deSDaniel Fojt 
1066085658deSDaniel Fojt static int
__archive_sha384init(archive_sha384_ctx * ctx)1067085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
1068085658deSDaniel Fojt {
1069085658deSDaniel Fojt   mbedtls_sha512_init(ctx);
1070085658deSDaniel Fojt   if (mbedtls_sha512_starts_ret(ctx, 1) == 0)
1071085658deSDaniel Fojt     return (ARCHIVE_OK);
1072085658deSDaniel Fojt   else
1073085658deSDaniel Fojt     return (ARCHIVE_FATAL);
1074085658deSDaniel Fojt }
1075085658deSDaniel Fojt 
1076085658deSDaniel Fojt static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)1077085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
1078085658deSDaniel Fojt     size_t insize)
1079085658deSDaniel Fojt {
1080085658deSDaniel Fojt   if (mbedtls_sha512_update_ret(ctx, indata, insize) == 0)
1081085658deSDaniel Fojt     return (ARCHIVE_OK);
1082085658deSDaniel Fojt   else
1083085658deSDaniel Fojt     return (ARCHIVE_FATAL);
1084085658deSDaniel Fojt }
1085085658deSDaniel Fojt 
1086085658deSDaniel Fojt static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)1087085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
1088085658deSDaniel Fojt {
1089085658deSDaniel Fojt   if (mbedtls_sha512_finish_ret(ctx, md) == 0) {
1090085658deSDaniel Fojt     mbedtls_sha512_free(ctx);
1091085658deSDaniel Fojt     return (ARCHIVE_OK);
1092085658deSDaniel Fojt   } else {
1093085658deSDaniel Fojt     mbedtls_sha512_free(ctx);
1094085658deSDaniel Fojt     return (ARCHIVE_FATAL);
1095085658deSDaniel Fojt   }
1096085658deSDaniel Fojt }
1097085658deSDaniel Fojt 
10986b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE)
10996b384f39SPeter Avalos 
11006b384f39SPeter Avalos static int
__archive_sha384init(archive_sha384_ctx * ctx)1101085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
11026b384f39SPeter Avalos {
11036b384f39SPeter Avalos   sha384_init(ctx);
11046b384f39SPeter Avalos   return (ARCHIVE_OK);
11056b384f39SPeter Avalos }
11066b384f39SPeter Avalos 
11076b384f39SPeter Avalos static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)1108085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
11096b384f39SPeter Avalos     size_t insize)
11106b384f39SPeter Avalos {
11116b384f39SPeter Avalos   sha384_update(ctx, insize, indata);
11126b384f39SPeter Avalos   return (ARCHIVE_OK);
11136b384f39SPeter Avalos }
11146b384f39SPeter Avalos 
11156b384f39SPeter Avalos static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)1116085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
11176b384f39SPeter Avalos {
11186b384f39SPeter Avalos   sha384_digest(ctx, SHA384_DIGEST_SIZE, md);
11196b384f39SPeter Avalos   return (ARCHIVE_OK);
11206b384f39SPeter Avalos }
11216b384f39SPeter Avalos 
11226b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL)
11236b384f39SPeter Avalos 
11246b384f39SPeter Avalos static int
__archive_sha384init(archive_sha384_ctx * ctx)1125085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
11266b384f39SPeter Avalos {
1127e95abc47Szrj   if ((*ctx = EVP_MD_CTX_new()) == NULL)
1128e95abc47Szrj 	return (ARCHIVE_FAILED);
1129*50f8aa9cSAntonio Huete Jimenez   if (!EVP_DigestInit(*ctx, EVP_sha384()))
1130*50f8aa9cSAntonio Huete Jimenez 	return (ARCHIVE_FAILED);
11316b384f39SPeter Avalos   return (ARCHIVE_OK);
11326b384f39SPeter Avalos }
11336b384f39SPeter Avalos 
11346b384f39SPeter Avalos static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)1135085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
11366b384f39SPeter Avalos     size_t insize)
11376b384f39SPeter Avalos {
1138e95abc47Szrj   EVP_DigestUpdate(*ctx, indata, insize);
11396b384f39SPeter Avalos   return (ARCHIVE_OK);
11406b384f39SPeter Avalos }
11416b384f39SPeter Avalos 
11426b384f39SPeter Avalos static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)1143085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
11446b384f39SPeter Avalos {
1145e95abc47Szrj   if (*ctx) {
1146e95abc47Szrj     EVP_DigestFinal(*ctx, md, NULL);
1147e95abc47Szrj     EVP_MD_CTX_free(*ctx);
1148e95abc47Szrj     *ctx = NULL;
1149e95abc47Szrj   }
11506b384f39SPeter Avalos   return (ARCHIVE_OK);
11516b384f39SPeter Avalos }
11526b384f39SPeter Avalos 
11536b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA384_WIN)
11546b384f39SPeter Avalos 
11556b384f39SPeter Avalos static int
__archive_sha384init(archive_sha384_ctx * ctx)1156085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
11576b384f39SPeter Avalos {
11586b384f39SPeter Avalos   return (win_crypto_init(ctx, CALG_SHA_384));
11596b384f39SPeter Avalos }
11606b384f39SPeter Avalos 
11616b384f39SPeter Avalos static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)1162085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
11636b384f39SPeter Avalos     size_t insize)
11646b384f39SPeter Avalos {
11656b384f39SPeter Avalos   return (win_crypto_Update(ctx, indata, insize));
11666b384f39SPeter Avalos }
11676b384f39SPeter Avalos 
11686b384f39SPeter Avalos static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)1169085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
11706b384f39SPeter Avalos {
11716b384f39SPeter Avalos   return (win_crypto_Final(md, 48, ctx));
11726b384f39SPeter Avalos }
11736b384f39SPeter Avalos 
11746b384f39SPeter Avalos #else
11756b384f39SPeter Avalos 
11766b384f39SPeter Avalos static int
__archive_sha384init(archive_sha384_ctx * ctx)1177085658deSDaniel Fojt __archive_sha384init(archive_sha384_ctx *ctx)
11786b384f39SPeter Avalos {
11796b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
11806b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
11816b384f39SPeter Avalos }
11826b384f39SPeter Avalos 
11836b384f39SPeter Avalos static int
__archive_sha384update(archive_sha384_ctx * ctx,const void * indata,size_t insize)1184085658deSDaniel Fojt __archive_sha384update(archive_sha384_ctx *ctx, const void *indata,
11856b384f39SPeter Avalos     size_t insize)
11866b384f39SPeter Avalos {
11876b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
11886b384f39SPeter Avalos 	(void)indata; /* UNUSED */
11896b384f39SPeter Avalos 	(void)insize; /* UNUSED */
11906b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
11916b384f39SPeter Avalos }
11926b384f39SPeter Avalos 
11936b384f39SPeter Avalos static int
__archive_sha384final(archive_sha384_ctx * ctx,void * md)1194085658deSDaniel Fojt __archive_sha384final(archive_sha384_ctx *ctx, void *md)
11956b384f39SPeter Avalos {
11966b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
11976b384f39SPeter Avalos 	(void)md; /* UNUSED */
11986b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
11996b384f39SPeter Avalos }
12006b384f39SPeter Avalos 
12016b384f39SPeter Avalos #endif
12026b384f39SPeter Avalos 
12036b384f39SPeter Avalos /* SHA512 implementations */
12046b384f39SPeter Avalos #if defined(ARCHIVE_CRYPTO_SHA512_LIBC)
12056b384f39SPeter Avalos 
12066b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1207085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
12086b384f39SPeter Avalos {
12096b384f39SPeter Avalos   SHA512_Init(ctx);
12106b384f39SPeter Avalos   return (ARCHIVE_OK);
12116b384f39SPeter Avalos }
12126b384f39SPeter Avalos 
12136b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1214085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
12156b384f39SPeter Avalos     size_t insize)
12166b384f39SPeter Avalos {
12176b384f39SPeter Avalos   SHA512_Update(ctx, indata, insize);
12186b384f39SPeter Avalos   return (ARCHIVE_OK);
12196b384f39SPeter Avalos }
12206b384f39SPeter Avalos 
12216b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1222085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
12236b384f39SPeter Avalos {
12246b384f39SPeter Avalos   SHA512_Final(md, ctx);
12256b384f39SPeter Avalos   return (ARCHIVE_OK);
12266b384f39SPeter Avalos }
12276b384f39SPeter Avalos 
12286b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA512_LIBC2)
12296b384f39SPeter Avalos 
12306b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1231085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
12326b384f39SPeter Avalos {
12336b384f39SPeter Avalos   SHA512Init(ctx);
12346b384f39SPeter Avalos   return (ARCHIVE_OK);
12356b384f39SPeter Avalos }
12366b384f39SPeter Avalos 
12376b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1238085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
12396b384f39SPeter Avalos     size_t insize)
12406b384f39SPeter Avalos {
12416b384f39SPeter Avalos   SHA512Update(ctx, indata, insize);
12426b384f39SPeter Avalos   return (ARCHIVE_OK);
12436b384f39SPeter Avalos }
12446b384f39SPeter Avalos 
12456b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1246085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
12476b384f39SPeter Avalos {
12486b384f39SPeter Avalos   SHA512Final(md, ctx);
12496b384f39SPeter Avalos   return (ARCHIVE_OK);
12506b384f39SPeter Avalos }
12516b384f39SPeter Avalos 
12526b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA512_LIBC3)
12536b384f39SPeter Avalos 
12546b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1255085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
12566b384f39SPeter Avalos {
12576b384f39SPeter Avalos   SHA512Init(ctx);
12586b384f39SPeter Avalos   return (ARCHIVE_OK);
12596b384f39SPeter Avalos }
12606b384f39SPeter Avalos 
12616b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1262085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
12636b384f39SPeter Avalos     size_t insize)
12646b384f39SPeter Avalos {
12656b384f39SPeter Avalos   SHA512Update(ctx, indata, insize);
12666b384f39SPeter Avalos   return (ARCHIVE_OK);
12676b384f39SPeter Avalos }
12686b384f39SPeter Avalos 
12696b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1270085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
12716b384f39SPeter Avalos {
12726b384f39SPeter Avalos   SHA512Final(md, ctx);
12736b384f39SPeter Avalos   return (ARCHIVE_OK);
12746b384f39SPeter Avalos }
12756b384f39SPeter Avalos 
12766b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA512_LIBMD)
12776b384f39SPeter Avalos 
12786b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1279085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
12806b384f39SPeter Avalos {
12816b384f39SPeter Avalos   SHA512_Init(ctx);
12826b384f39SPeter Avalos   return (ARCHIVE_OK);
12836b384f39SPeter Avalos }
12846b384f39SPeter Avalos 
12856b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1286085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
12876b384f39SPeter Avalos     size_t insize)
12886b384f39SPeter Avalos {
12896b384f39SPeter Avalos   SHA512_Update(ctx, indata, insize);
12906b384f39SPeter Avalos   return (ARCHIVE_OK);
12916b384f39SPeter Avalos }
12926b384f39SPeter Avalos 
12936b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1294085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
12956b384f39SPeter Avalos {
12966b384f39SPeter Avalos   SHA512_Final(md, ctx);
12976b384f39SPeter Avalos   return (ARCHIVE_OK);
12986b384f39SPeter Avalos }
12996b384f39SPeter Avalos 
13006b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM)
13016b384f39SPeter Avalos 
13026b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1303085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
13046b384f39SPeter Avalos {
13056b384f39SPeter Avalos   CC_SHA512_Init(ctx);
13066b384f39SPeter Avalos   return (ARCHIVE_OK);
13076b384f39SPeter Avalos }
13086b384f39SPeter Avalos 
13096b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1310085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
13116b384f39SPeter Avalos     size_t insize)
13126b384f39SPeter Avalos {
13136b384f39SPeter Avalos   CC_SHA512_Update(ctx, indata, insize);
13146b384f39SPeter Avalos   return (ARCHIVE_OK);
13156b384f39SPeter Avalos }
13166b384f39SPeter Avalos 
13176b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1318085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
13196b384f39SPeter Avalos {
13206b384f39SPeter Avalos   CC_SHA512_Final(md, ctx);
13216b384f39SPeter Avalos   return (ARCHIVE_OK);
13226b384f39SPeter Avalos }
13236b384f39SPeter Avalos 
1324085658deSDaniel Fojt #elif defined(ARCHIVE_CRYPTO_SHA512_MBEDTLS)
1325085658deSDaniel Fojt 
1326085658deSDaniel Fojt static int
__archive_sha512init(archive_sha512_ctx * ctx)1327085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
1328085658deSDaniel Fojt {
1329085658deSDaniel Fojt   mbedtls_sha512_init(ctx);
1330085658deSDaniel Fojt   if (mbedtls_sha512_starts_ret(ctx, 0) == 0)
1331085658deSDaniel Fojt     return (ARCHIVE_OK);
1332085658deSDaniel Fojt   else
1333085658deSDaniel Fojt     return (ARCHIVE_FATAL);
1334085658deSDaniel Fojt }
1335085658deSDaniel Fojt 
1336085658deSDaniel Fojt static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1337085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
1338085658deSDaniel Fojt     size_t insize)
1339085658deSDaniel Fojt {
1340085658deSDaniel Fojt   if (mbedtls_sha512_update_ret(ctx, indata, insize) == 0)
1341085658deSDaniel Fojt     return (ARCHIVE_OK);
1342085658deSDaniel Fojt   else
1343085658deSDaniel Fojt     return (ARCHIVE_FATAL);
1344085658deSDaniel Fojt }
1345085658deSDaniel Fojt 
1346085658deSDaniel Fojt static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1347085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
1348085658deSDaniel Fojt {
1349085658deSDaniel Fojt   if (mbedtls_sha512_finish_ret(ctx, md) == 0) {
1350085658deSDaniel Fojt     mbedtls_sha512_free(ctx);
1351085658deSDaniel Fojt     return (ARCHIVE_OK);
1352085658deSDaniel Fojt   } else {
1353085658deSDaniel Fojt     mbedtls_sha512_free(ctx);
1354085658deSDaniel Fojt     return (ARCHIVE_FATAL);
1355085658deSDaniel Fojt   }
1356085658deSDaniel Fojt }
1357085658deSDaniel Fojt 
13586b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE)
13596b384f39SPeter Avalos 
13606b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1361085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
13626b384f39SPeter Avalos {
13636b384f39SPeter Avalos   sha512_init(ctx);
13646b384f39SPeter Avalos   return (ARCHIVE_OK);
13656b384f39SPeter Avalos }
13666b384f39SPeter Avalos 
13676b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1368085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
13696b384f39SPeter Avalos     size_t insize)
13706b384f39SPeter Avalos {
13716b384f39SPeter Avalos   sha512_update(ctx, insize, indata);
13726b384f39SPeter Avalos   return (ARCHIVE_OK);
13736b384f39SPeter Avalos }
13746b384f39SPeter Avalos 
13756b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1376085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
13776b384f39SPeter Avalos {
13786b384f39SPeter Avalos   sha512_digest(ctx, SHA512_DIGEST_SIZE, md);
13796b384f39SPeter Avalos   return (ARCHIVE_OK);
13806b384f39SPeter Avalos }
13816b384f39SPeter Avalos 
13826b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL)
13836b384f39SPeter Avalos 
13846b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1385085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
13866b384f39SPeter Avalos {
1387e95abc47Szrj   if ((*ctx = EVP_MD_CTX_new()) == NULL)
1388e95abc47Szrj 	return (ARCHIVE_FAILED);
1389*50f8aa9cSAntonio Huete Jimenez   if (!EVP_DigestInit(*ctx, EVP_sha512()))
1390*50f8aa9cSAntonio Huete Jimenez 	return (ARCHIVE_FAILED);
13916b384f39SPeter Avalos   return (ARCHIVE_OK);
13926b384f39SPeter Avalos }
13936b384f39SPeter Avalos 
13946b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1395085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
13966b384f39SPeter Avalos     size_t insize)
13976b384f39SPeter Avalos {
1398e95abc47Szrj   EVP_DigestUpdate(*ctx, indata, insize);
13996b384f39SPeter Avalos   return (ARCHIVE_OK);
14006b384f39SPeter Avalos }
14016b384f39SPeter Avalos 
14026b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1403085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
14046b384f39SPeter Avalos {
1405e95abc47Szrj   if (*ctx) {
1406e95abc47Szrj     EVP_DigestFinal(*ctx, md, NULL);
1407e95abc47Szrj     EVP_MD_CTX_free(*ctx);
1408e95abc47Szrj     *ctx = NULL;
1409e95abc47Szrj   }
14106b384f39SPeter Avalos   return (ARCHIVE_OK);
14116b384f39SPeter Avalos }
14126b384f39SPeter Avalos 
14136b384f39SPeter Avalos #elif defined(ARCHIVE_CRYPTO_SHA512_WIN)
14146b384f39SPeter Avalos 
14156b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1416085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
14176b384f39SPeter Avalos {
14186b384f39SPeter Avalos   return (win_crypto_init(ctx, CALG_SHA_512));
14196b384f39SPeter Avalos }
14206b384f39SPeter Avalos 
14216b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1422085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
14236b384f39SPeter Avalos     size_t insize)
14246b384f39SPeter Avalos {
14256b384f39SPeter Avalos   return (win_crypto_Update(ctx, indata, insize));
14266b384f39SPeter Avalos }
14276b384f39SPeter Avalos 
14286b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1429085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
14306b384f39SPeter Avalos {
14316b384f39SPeter Avalos   return (win_crypto_Final(md, 64, ctx));
14326b384f39SPeter Avalos }
14336b384f39SPeter Avalos 
14346b384f39SPeter Avalos #else
14356b384f39SPeter Avalos 
14366b384f39SPeter Avalos static int
__archive_sha512init(archive_sha512_ctx * ctx)1437085658deSDaniel Fojt __archive_sha512init(archive_sha512_ctx *ctx)
14386b384f39SPeter Avalos {
14396b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
14406b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
14416b384f39SPeter Avalos }
14426b384f39SPeter Avalos 
14436b384f39SPeter Avalos static int
__archive_sha512update(archive_sha512_ctx * ctx,const void * indata,size_t insize)1444085658deSDaniel Fojt __archive_sha512update(archive_sha512_ctx *ctx, const void *indata,
14456b384f39SPeter Avalos     size_t insize)
14466b384f39SPeter Avalos {
14476b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
14486b384f39SPeter Avalos 	(void)indata; /* UNUSED */
14496b384f39SPeter Avalos 	(void)insize; /* UNUSED */
14506b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
14516b384f39SPeter Avalos }
14526b384f39SPeter Avalos 
14536b384f39SPeter Avalos static int
__archive_sha512final(archive_sha512_ctx * ctx,void * md)1454085658deSDaniel Fojt __archive_sha512final(archive_sha512_ctx *ctx, void *md)
14556b384f39SPeter Avalos {
14566b384f39SPeter Avalos 	(void)ctx; /* UNUSED */
14576b384f39SPeter Avalos 	(void)md; /* UNUSED */
14586b384f39SPeter Avalos 	return (ARCHIVE_FAILED);
14596b384f39SPeter Avalos }
14606b384f39SPeter Avalos 
14616b384f39SPeter Avalos #endif
14626b384f39SPeter Avalos 
14636b384f39SPeter Avalos /* NOTE: Message Digest functions are set based on availability and by the
14646b384f39SPeter Avalos  * following order of preference.
14656b384f39SPeter Avalos  * 1. libc
14666b384f39SPeter Avalos  * 2. libc2
14676b384f39SPeter Avalos  * 3. libc3
14686b384f39SPeter Avalos  * 4. libSystem
14696b384f39SPeter Avalos  * 5. Nettle
14706b384f39SPeter Avalos  * 6. OpenSSL
14716b384f39SPeter Avalos  * 7. libmd
14726b384f39SPeter Avalos  * 8. Windows API
14736b384f39SPeter Avalos  */
14746b384f39SPeter Avalos const struct archive_digest __archive_digest =
14756b384f39SPeter Avalos {
14766b384f39SPeter Avalos /* MD5 */
1477085658deSDaniel Fojt   &__archive_md5init,
1478085658deSDaniel Fojt   &__archive_md5update,
1479085658deSDaniel Fojt   &__archive_md5final,
14806b384f39SPeter Avalos 
14816b384f39SPeter Avalos /* RIPEMD160 */
1482085658deSDaniel Fojt   &__archive_ripemd160init,
1483085658deSDaniel Fojt   &__archive_ripemd160update,
1484085658deSDaniel Fojt   &__archive_ripemd160final,
14856b384f39SPeter Avalos 
14866b384f39SPeter Avalos /* SHA1 */
1487085658deSDaniel Fojt   &__archive_sha1init,
1488085658deSDaniel Fojt   &__archive_sha1update,
1489085658deSDaniel Fojt   &__archive_sha1final,
14906b384f39SPeter Avalos 
14916b384f39SPeter Avalos /* SHA256 */
1492085658deSDaniel Fojt   &__archive_sha256init,
1493085658deSDaniel Fojt   &__archive_sha256update,
1494085658deSDaniel Fojt   &__archive_sha256final,
14956b384f39SPeter Avalos 
14966b384f39SPeter Avalos /* SHA384 */
1497085658deSDaniel Fojt   &__archive_sha384init,
1498085658deSDaniel Fojt   &__archive_sha384update,
1499085658deSDaniel Fojt   &__archive_sha384final,
15006b384f39SPeter Avalos 
15016b384f39SPeter Avalos /* SHA512 */
1502085658deSDaniel Fojt   &__archive_sha512init,
1503085658deSDaniel Fojt   &__archive_sha512update,
1504085658deSDaniel Fojt   &__archive_sha512final
15056b384f39SPeter Avalos };
1506