/* This code is written by kerukuro for cppcrypto library (http://cppcrypto.sourceforge.net/) and released into public domain. */ /* adapted for VeraCrypt */ #include "chacha256.h" #include "cpu.h" #include "misc.h" #define rotater32(x,n) rotr32(x, n) #define rotatel32(x,n) rotl32(x, n) #if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE void chacha_ECRYPT_encrypt_bytes(size_t bytes, uint32* x, const unsigned char* m, unsigned char* out, unsigned char* output, unsigned int r); #endif static VC_INLINE void xor_block_512(const unsigned char* in, const unsigned char* prev, unsigned char* out) { #if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && !defined(_UEFI) && (!defined (TC_WINDOWS_DRIVER) || (!defined (DEBUG) && defined (_WIN64))) if (HasSSE2()) { __m128i b1 = _mm_loadu_si128((const __m128i*) in); __m128i p1 = _mm_loadu_si128((const __m128i*) prev); __m128i b2 = _mm_loadu_si128((const __m128i*) (in + 16)); __m128i p2 = _mm_loadu_si128((const __m128i*) (prev + 16)); _mm_storeu_si128((__m128i*) out, _mm_xor_si128(b1, p1)); _mm_storeu_si128((__m128i*) (out + 16), _mm_xor_si128(b2, p2)); b1 = _mm_loadu_si128((const __m128i*) (in + 32)); p1 = _mm_loadu_si128((const __m128i*) (prev + 32)); b2 = _mm_loadu_si128((const __m128i*) (in + 48)); p2 = _mm_loadu_si128((const __m128i*) (prev + 48)); _mm_storeu_si128((__m128i*) (out + 32), _mm_xor_si128(b1, p1)); _mm_storeu_si128((__m128i*) (out + 48), _mm_xor_si128(b2, p2)); } else #endif { int i; for (i = 0; i < 64; i++) out[i] = in[i] ^ prev[i]; } } static VC_INLINE void chacha_core(uint32* x, int r) { int i; for (i = 0; i < r; i++) { x[0] += x[4]; x[12] = rotatel32(x[12] ^ x[0], 16); x[8] += x[12]; x[4] = rotatel32(x[4] ^ x[8], 12); x[0] += x[4]; x[12] = rotatel32(x[12] ^ x[0], 8); x[8] += x[12]; x[4] = rotatel32(x[4] ^ x[8], 7); x[1] += x[5]; x[13] = rotatel32(x[13] ^ x[1], 16); x[9] += x[13]; x[5] = rotatel32(x[5] ^ x[9], 12); x[1] += x[5]; x[13] = rotatel32(x[13] ^ x[1], 8); x[9] += x[13]; x[5] = rotatel32(x[5] ^ x[9], 7); x[2] += x[6]; x[14] = rotatel32(x[14] ^ x[2], 16); x[10] += x[14]; x[6] = rotatel32(x[6] ^ x[10], 12); x[2] += x[6]; x[14] = rotatel32(x[14] ^ x[2], 8); x[10] += x[14]; x[6] = rotatel32(x[6] ^ x[10], 7); x[3] += x[7]; x[15] = rotatel32(x[15] ^ x[3], 16); x[11] += x[15]; x[7] = rotatel32(x[7] ^ x[11], 12); x[3] += x[7]; x[15] = rotatel32(x[15] ^ x[3], 8); x[11] += x[15]; x[7] = rotatel32(x[7] ^ x[11], 7); x[0] += x[5]; x[15] = rotatel32(x[15] ^ x[0], 16); x[10] += x[15]; x[5] = rotatel32(x[5] ^ x[10], 12); x[0] += x[5]; x[15] = rotatel32(x[15] ^ x[0], 8); x[10] += x[15]; x[5] = rotatel32(x[5] ^ x[10], 7); x[1] += x[6]; x[12] = rotatel32(x[12] ^ x[1], 16); x[11] += x[12]; x[6] = rotatel32(x[6] ^ x[11], 12); x[1] += x[6]; x[12] = rotatel32(x[12] ^ x[1], 8); x[11] += x[12]; x[6] = rotatel32(x[6] ^ x[11], 7); x[2] += x[7]; x[13] = rotatel32(x[13] ^ x[2], 16); x[8] += x[13]; x[7] = rotatel32(x[7] ^ x[8], 12); x[2] += x[7]; x[13] = rotatel32(x[13] ^ x[2], 8); x[8] += x[13]; x[7] = rotatel32(x[7] ^ x[8], 7); x[3] += x[4]; x[14] = rotatel32(x[14] ^ x[3], 16); x[9] += x[14]; x[4] = rotatel32(x[4] ^ x[9], 12); x[3] += x[4]; x[14] = rotatel32(x[14] ^ x[3], 8); x[9] += x[14]; x[4] = rotatel32(x[4] ^ x[9], 7); } } static VC_INLINE void chacha_hash(const uint32* in, uint32* out, int r) { uint32 x[16]; int i; memcpy(x, in, 64); chacha_core(x, r); for (i = 0; i < 16; ++i) out[i] = x[i] + in[i]; } static VC_INLINE void incrementSalsaCounter(uint32* input, uint32* block, int r) { chacha_hash(input, block, r); if (!++input[12]) ++input[13]; } static VC_INLINE void do_encrypt(const unsigned char* in, size_t len, unsigned char* out, int r, size_t* posPtr, uint32* input, uint32* block) { size_t i = 0, pos = *posPtr; if (pos) { while (pos < len && pos < 64) { out[i] = in[i] ^ ((unsigned char*)block)[pos++]; ++i; } len -= i; } if (len) pos = 0; #if CRYPTOPP_SSSE3_AVAILABLE && !defined(_UEFI) && (!defined (TC_WINDOWS_DRIVER) || (!defined (DEBUG) && defined (_WIN64))) if (HasSSSE3()) { size_t fullblocks = len - len % 64; if (fullblocks) { chacha_ECRYPT_encrypt_bytes(fullblocks, input, in + i, out + i, (unsigned char*)block, r); i += fullblocks; len -= fullblocks; } if (len) { chacha_ECRYPT_encrypt_bytes(len, input, in + i, out + i, (unsigned char*)block, r); pos = len; } *posPtr = pos; return; } #endif for (; len; len -= VC_MIN(64, len)) { incrementSalsaCounter(input, block, r); if (len >= 64) { xor_block_512(in + i, (unsigned char*)block, out + i); i += 64; } else { for (; pos < len; pos++, i++) out[i] = in[i] ^ ((unsigned char*)block)[pos]; } } *posPtr = pos; } void ChaCha256Init(ChaCha256Ctx* ctx, const unsigned char* key, const unsigned char* iv, int rounds) { ctx->internalRounds = rounds / 2; ctx->pos = 0; ctx->input_[12] = 0; ctx->input_[13] = 0; memcpy(ctx->input_ + 4, key, 32); memcpy(ctx->input_ + 14, iv, 8); ctx->input_[0] = 0x61707865; ctx->input_[1] = 0x3320646E; ctx->input_[2] = 0x79622D32; ctx->input_[3] = 0x6B206574; } void ChaCha256Encrypt(ChaCha256Ctx* ctx, const unsigned char* in, size_t len, unsigned char* out) { do_encrypt(in, len, out, ctx->internalRounds, &ctx->pos, ctx->input_, ctx->block_); } Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
zip_source_is_deleted.c -- was archive was removed?
Copyright (C) 2014-2019 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT 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.
*/
#include "zipint.h"
ZIP_EXTERN int
zip_source_is_deleted(zip_source_t *src) {
return src->write_state == ZIP_SOURCE_WRITE_REMOVED;
}