| 1 | /* mz_strm_wzaes.c -- Stream for WinZip AES encryption |
| 2 | part of the minizip-ng project |
| 3 | |
| 4 | Copyright (C) Nathan Moinvaziri |
| 5 | https://github.com/zlib-ng/minizip-ng |
| 6 | Copyright (C) 1998-2010 Brian Gladman, Worcester, UK |
| 7 | |
| 8 | This program is distributed under the terms of the same license as zlib. |
| 9 | See the accompanying LICENSE file for the full text of the license. |
| 10 | */ |
| 11 | |
| 12 | #include "mz.h"cxx . . $ `<file>/mz.h`/ |
| 13 | #include "mz_crypt.h"cxx . . $ `<file>/mz_crypt.h`/ |
| 14 | #include "mz_strm.h"cxx . . $ `<file>/mz_strm.h`/ |
| 15 | #include "mz_strm_wzaes.h"cxx . . $ `<file>/mz_strm_wzaes.h`/ |
| 16 | |
| 17 | /***************************************************************************/ |
| 18 | |
| 19 | #define MZ_AES_KEY_LENGTHcxx . . $ `mz_strm_wzaes.c:19:9`!(STRENGTH) (8 * (STRENGTH & 3) + 8) |
| 20 | #define MZ_AES_KEYING_ITERATIONScxx . . $ `mz_strm_wzaes.c:20:9`! (1000) |
| 21 | #define MZ_AES_SALT_LENGTHcxx . . $ `mz_strm_wzaes.c:21:9`!(STRENGTH) (4 * (STRENGTH & 3) + 4) |
| 22 | #define MZ_AES_SALT_LENGTH_MAXcxx . . $ `mz_strm_wzaes.c:22:9`! (16) |
| 23 | #define MZ_AES_PW_LENGTH_MAXcxx . . $ `mz_strm_wzaes.c:23:9`! (128) |
| 24 | #define MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`! (2) |
| 25 | #define MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`! (10) |
| 26 | |
| 27 | /***************************************************************************/ |
| 28 | |
| 29 | static mz_stream_vtblcxx . . $ mz_stream_vtbl# mz_stream_wzaes_vtblcxx . . $ mz_stream_wzaes_vtbl. = { |
| 30 | mz_stream_wzaes_opencxx . . $ mz_stream_wzaes_open(7083a8984c0735e8)., mz_stream_wzaes_is_opencxx . . $ mz_stream_wzaes_is_open(dedf1e9b1c614a07)., mz_stream_wzaes_readcxx . . $ mz_stream_wzaes_read(8bc41909eac9e5d8)., mz_stream_wzaes_writecxx . . $ mz_stream_wzaes_write(91e54fd90adbb21)., |
| 31 | mz_stream_wzaes_tellcxx . . $ mz_stream_wzaes_tell(72c1818a5177f981)., mz_stream_wzaes_seekcxx . . $ mz_stream_wzaes_seek(8bc0ff128761c75d)., mz_stream_wzaes_closecxx . . $ mz_stream_wzaes_close(dedf1e9b1c614a07)., mz_stream_wzaes_errorcxx . . $ mz_stream_wzaes_error(dedf1e9b1c614a07)., |
| 32 | mz_stream_wzaes_createcxx . . $ mz_stream_wzaes_create(50c7df7de5344ebb)., mz_stream_wzaes_deletecxx . . $ mz_stream_wzaes_delete(539e082cf00e1f43)., mz_stream_wzaes_get_prop_int64cxx . . $ mz_stream_wzaes_get_prop_int64(280df70541557ec8)., mz_stream_wzaes_set_prop_int64cxx . . $ mz_stream_wzaes_set_prop_int64(5f4b2ff0df22ef2b).}; |
| 33 | |
| 34 | /***************************************************************************/ |
| 35 | |
| 36 | typedef struct mz_stream_wzaes_scxx . . $ mz_stream_wzaes_s# { |
| 37 | mz_streamcxx . . $ mz_stream# streamcxx . . $ mz_stream_wzaes_s#stream.; |
| 38 | int32_tcxx . . $ int32_t# modecxx . . $ mz_stream_wzaes_s#mode.; |
| 39 | int32_tcxx . . $ int32_t# errorcxx . . $ mz_stream_wzaes_s#error.; |
| 40 | int16_tcxx . . $ int16_t# initializedcxx . . $ mz_stream_wzaes_s#initialized.; |
| 41 | uint8_tcxx . . $ uint8_t# buffercxx . . $ mz_stream_wzaes_s#buffer.[UINT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:117:10`!]; |
| 42 | int64_tcxx . . $ int64_t# total_incxx . . $ mz_stream_wzaes_s#total_in.; |
| 43 | int64_tcxx . . $ int64_t# max_total_incxx . . $ mz_stream_wzaes_s#max_total_in.; |
| 44 | int64_tcxx . . $ int64_t# total_outcxx . . $ mz_stream_wzaes_s#total_out.; |
| 45 | uint8_tcxx . . $ uint8_t# strengthcxx . . $ mz_stream_wzaes_s#strength.; |
| 46 | const char *passwordcxx . . $ mz_stream_wzaes_s#password.; |
| 47 | void *aescxx . . $ mz_stream_wzaes_s#aes.; |
| 48 | uint32_tcxx . . $ uint32_t# crypt_poscxx . . $ mz_stream_wzaes_s#crypt_pos.; |
| 49 | uint8_tcxx . . $ uint8_t# crypt_blockcxx . . $ mz_stream_wzaes_s#crypt_block.[MZ_AES_BLOCK_SIZEcxx . . $ `mz.h:121:9`!]; |
| 50 | void *hmaccxx . . $ mz_stream_wzaes_s#hmac.; |
| 51 | uint8_tcxx . . $ uint8_t# noncecxx . . $ mz_stream_wzaes_s#nonce.[MZ_AES_BLOCK_SIZEcxx . . $ `mz.h:121:9`!]; |
| 52 | } mz_stream_wzaescxx . . $ mz_stream_wzaes#; |
| 53 | |
| 54 | /***************************************************************************/ |
| 55 | |
| 56 | int32_tcxx . . $ int32_t# mz_stream_wzaes_opencxx . . $ mz_stream_wzaes_open(7083a8984c0735e8).(void *stream, const char *path, int32_tcxx . . $ int32_t# mode) { |
| 57 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 58 | uint16_tcxx . . $ uint16_t# salt_length = 0; |
| 59 | uint16_tcxx . . $ uint16_t# password_length = 0; |
| 60 | uint16_tcxx . . $ uint16_t# key_length = 0; |
| 61 | uint8_tcxx . . $ uint8_t# kbuf[2 * MZ_AES_KEY_LENGTH_MAXcxx . . $ `mz.h:120:9`! + MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!]; |
| 62 | uint8_tcxx . . $ uint8_t# verify[MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!]; |
| 63 | uint8_tcxx . . $ uint8_t# verify_expected[MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!]; |
| 64 | uint8_tcxx . . $ uint8_t# salt_value[MZ_AES_SALT_LENGTH_MAXcxx . . $ `mz_strm_wzaes.c:22:9`!]; |
| 65 | const char *password = path; |
| 66 | |
| 67 | wzaes->total_incxx . . $ mz_stream_wzaes_s#total_in. = 0; |
| 68 | wzaes->total_outcxx . . $ mz_stream_wzaes_s#total_out. = 0; |
| 69 | wzaes->initializedcxx . . $ mz_stream_wzaes_s#initialized. = 0; |
| 70 | |
| 71 | if (mz_stream_is_opencxx . . $ mz_stream_is_open(dedf1e9b1c614a07).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base.) != MZ_OKcxx . . $ `mz.h:21:9`!) |
| 72 | return MZ_OPEN_ERRORcxx . . $ `mz.h:40:9`!; |
| 73 | |
| 74 | if (!password) |
| 75 | password = wzaes->passwordcxx . . $ mz_stream_wzaes_s#password.; |
| 76 | if (!password) |
| 77 | return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!; |
| 78 | password_length = (uint16_tcxx . . $ uint16_t#)strlencxx . . $ strlen(751346f8406fd082).(password); |
| 79 | if (password_length > MZ_AES_PW_LENGTH_MAXcxx . . $ `mz_strm_wzaes.c:23:9`!) |
| 80 | return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!; |
| 81 | |
| 82 | if (wzaes->strengthcxx . . $ mz_stream_wzaes_s#strength. < 1 || wzaes->strengthcxx . . $ mz_stream_wzaes_s#strength. > 3) |
| 83 | return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!; |
| 84 | |
| 85 | key_length = MZ_AES_KEY_LENGTHcxx . . $ `mz_strm_wzaes.c:19:9`!(wzaes->strength); |
| 86 | salt_length = MZ_AES_SALT_LENGTHcxx . . $ `mz_strm_wzaes.c:21:9`!(wzaes->strength); |
| 87 | |
| 88 | if (mode & MZ_OPEN_MODE_WRITEcxx . . $ `mz.h:51:9`!) { |
| 89 | mz_crypt_randcxx . . $ mz_crypt_rand(7405b416d0535413).(salt_value, salt_length); |
| 90 | } else if (mode & MZ_OPEN_MODE_READcxx . . $ `mz.h:50:9`!) { |
| 91 | if (mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., salt_value, salt_length) != salt_length) |
| 92 | return MZ_READ_ERRORcxx . . $ `mz.h:44:9`!; |
| 93 | } |
| 94 | |
| 95 | /* Derive the encryption and authentication keys and the password verifier */ |
| 96 | mz_crypt_pbkdf2cxx . . $ mz_crypt_pbkdf2(94d1319d89cfb21a).((uint8_tcxx . . $ uint8_t# *)password, password_length, salt_value, salt_length, MZ_AES_KEYING_ITERATIONScxx . . $ `mz_strm_wzaes.c:20:9`!, kbuf, |
| 97 | 2 * key_length + MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!); |
| 98 | |
| 99 | /* Initialize the buffer pos */ |
| 100 | wzaes->crypt_poscxx . . $ mz_stream_wzaes_s#crypt_pos. = MZ_AES_BLOCK_SIZEcxx . . $ `mz.h:121:9`!; |
| 101 | |
| 102 | /* Use fixed zeroed IV/nonce for CTR mode */ |
| 103 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(wzaes->noncecxx . . $ mz_stream_wzaes_s#nonce., 0, sizeof(wzaes->noncecxx . . $ mz_stream_wzaes_s#nonce.)); |
| 104 | |
| 105 | /* Initialize for encryption using key 1 */ |
| 106 | mz_crypt_aes_resetcxx . . $ mz_crypt_aes_reset(5d22bdacc48458e8).(wzaes->aescxx . . $ mz_stream_wzaes_s#aes.); |
| 107 | mz_crypt_aes_set_encrypt_keycxx . . $ mz_crypt_aes_set_encrypt_key(73c51336f91d9328).(wzaes->aescxx . . $ mz_stream_wzaes_s#aes., kbuf, key_length, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, 0); |
| 108 | |
| 109 | /* Initialize for authentication using key 2 */ |
| 110 | mz_crypt_hmac_resetcxx . . $ mz_crypt_hmac_reset(5d22bdacc48458e8).(wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac.); |
| 111 | mz_crypt_hmac_set_algorithmcxx . . $ mz_crypt_hmac_set_algorithm(7ff71eb16271959b).(wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac., MZ_HASH_SHA1cxx . . $ `mz.h:127:9`!); |
| 112 | mz_crypt_hmac_initcxx . . $ mz_crypt_hmac_init(91e54fd90adbb21).(wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac., kbuf + key_length, key_length); |
| 113 | |
| 114 | memcpycxx . . $ memcpy(cc817cb175f282d).(verify, kbuf + (2 * key_length), MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!); |
| 115 | |
| 116 | if (mode & MZ_OPEN_MODE_WRITEcxx . . $ `mz.h:51:9`!) { |
| 117 | if (mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., salt_value, salt_length) != salt_length) |
| 118 | return MZ_WRITE_ERRORcxx . . $ `mz.h:45:9`!; |
| 119 | |
| 120 | wzaes->total_outcxx . . $ mz_stream_wzaes_s#total_out. += salt_length; |
| 121 | |
| 122 | if (mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., verify, MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!) != MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!) |
| 123 | return MZ_WRITE_ERRORcxx . . $ `mz.h:45:9`!; |
| 124 | |
| 125 | wzaes->total_outcxx . . $ mz_stream_wzaes_s#total_out. += MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!; |
| 126 | } else if (mode & MZ_OPEN_MODE_READcxx . . $ `mz.h:50:9`!) { |
| 127 | wzaes->total_incxx . . $ mz_stream_wzaes_s#total_in. += salt_length; |
| 128 | |
| 129 | if (mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., verify_expected, MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!) != MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!) |
| 130 | return MZ_READ_ERRORcxx . . $ `mz.h:44:9`!; |
| 131 | |
| 132 | wzaes->total_incxx . . $ mz_stream_wzaes_s#total_in. += MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!; |
| 133 | |
| 134 | if (memcmpcxx . . $ memcmp(36f949851efa3055).(verify_expected, verify, MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!) != 0) |
| 135 | return MZ_PASSWORD_ERRORcxx . . $ `mz.h:37:9`!; |
| 136 | } |
| 137 | |
| 138 | wzaes->modecxx . . $ mz_stream_wzaes_s#mode. = mode; |
| 139 | wzaes->initializedcxx . . $ mz_stream_wzaes_s#initialized. = 1; |
| 140 | |
| 141 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 142 | } |
| 143 | |
| 144 | int32_tcxx . . $ int32_t# mz_stream_wzaes_is_opencxx . . $ mz_stream_wzaes_is_open(dedf1e9b1c614a07).(void *stream) { |
| 145 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 146 | if (!wzaes->initializedcxx . . $ mz_stream_wzaes_s#initialized.) |
| 147 | return MZ_OPEN_ERRORcxx . . $ `mz.h:40:9`!; |
| 148 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 149 | } |
| 150 | |
| 151 | static int32_tcxx . . $ int32_t# mz_stream_wzaes_ctr_encryptcxx . . $ mz_stream_wzaes_ctr_encrypt(78b1a2a92e9cffd0).(void *stream, uint8_tcxx . . $ uint8_t# *buf, int32_tcxx . . $ int32_t# size) { |
| 152 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 153 | uint32_tcxx . . $ uint32_t# pos = wzaes->crypt_poscxx . . $ mz_stream_wzaes_s#crypt_pos.; |
| 154 | uint32_tcxx . . $ uint32_t# i = 0; |
| 155 | int32_tcxx . . $ int32_t# err = MZ_OKcxx . . $ `mz.h:21:9`!; |
| 156 | |
| 157 | while (i < (uint32_tcxx . . $ uint32_t#)size) { |
| 158 | if (pos == MZ_AES_BLOCK_SIZEcxx . . $ `mz.h:121:9`!) { |
| 159 | uint32_tcxx . . $ uint32_t# j = 0; |
| 160 | |
| 161 | /* Increment encryption nonce */ |
| 162 | while (j < 8 && !++wzaes->noncecxx . . $ mz_stream_wzaes_s#nonce.[j]) |
| 163 | j += 1; |
| 164 | |
| 165 | /* Encrypt the nonce using ECB mode to form next xor buffer */ |
| 166 | memcpycxx . . $ memcpy(cc817cb175f282d).(wzaes->crypt_blockcxx . . $ mz_stream_wzaes_s#crypt_block., wzaes->noncecxx . . $ mz_stream_wzaes_s#nonce., MZ_AES_BLOCK_SIZEcxx . . $ `mz.h:121:9`!); |
| 167 | mz_crypt_aes_encryptcxx . . $ mz_crypt_aes_encrypt(fd2b9c01f5c5ae7c).(wzaes->aescxx . . $ mz_stream_wzaes_s#aes., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, 0, wzaes->crypt_blockcxx . . $ mz_stream_wzaes_s#crypt_block., sizeof(wzaes->crypt_blockcxx . . $ mz_stream_wzaes_s#crypt_block.)); |
| 168 | pos = 0; |
| 169 | } |
| 170 | |
| 171 | buf[i++] ^= wzaes->crypt_blockcxx . . $ mz_stream_wzaes_s#crypt_block.[pos++]; |
| 172 | } |
| 173 | |
| 174 | wzaes->crypt_poscxx . . $ mz_stream_wzaes_s#crypt_pos. = pos; |
| 175 | return err; |
| 176 | } |
| 177 | |
| 178 | int32_tcxx . . $ int32_t# mz_stream_wzaes_readcxx . . $ mz_stream_wzaes_read(8bc41909eac9e5d8).(void *stream, void *buf, int32_tcxx . . $ int32_t# size) { |
| 179 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 180 | int64_tcxx . . $ int64_t# max_total_in = 0; |
| 181 | int32_tcxx . . $ int32_t# bytes_to_read = size; |
| 182 | int32_tcxx . . $ int32_t# read = 0; |
| 183 | |
| 184 | max_total_in = wzaes->max_total_incxx . . $ mz_stream_wzaes_s#max_total_in. - MZ_AES_FOOTER_SIZEcxx . . $ `mz.h:122:9`!; |
| 185 | if ((int64_tcxx . . $ int64_t#)bytes_to_read > (max_total_in - wzaes->total_incxx . . $ mz_stream_wzaes_s#total_in.)) |
| 186 | bytes_to_read = (int32_tcxx . . $ int32_t#)(max_total_in - wzaes->total_incxx . . $ mz_stream_wzaes_s#total_in.); |
| 187 | |
| 188 | read = mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., buf, bytes_to_read); |
| 189 | |
| 190 | if (read > 0) { |
| 191 | mz_crypt_hmac_updatecxx . . $ mz_crypt_hmac_update(91e54fd90adbb21).(wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac., (uint8_tcxx . . $ uint8_t# *)buf, read); |
| 192 | mz_stream_wzaes_ctr_encryptcxx . . $ mz_stream_wzaes_ctr_encrypt(78b1a2a92e9cffd0).(stream, (uint8_tcxx . . $ uint8_t# *)buf, read); |
| 193 | |
| 194 | wzaes->total_incxx . . $ mz_stream_wzaes_s#total_in. += read; |
| 195 | } |
| 196 | |
| 197 | return read; |
| 198 | } |
| 199 | |
| 200 | int32_tcxx . . $ int32_t# mz_stream_wzaes_writecxx . . $ mz_stream_wzaes_write(91e54fd90adbb21).(void *stream, const void *buf, int32_tcxx . . $ int32_t# size) { |
| 201 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 202 | const uint8_tcxx . . $ uint8_t# *buf_ptr = (const uint8_tcxx . . $ uint8_t# *)buf; |
| 203 | int32_tcxx . . $ int32_t# bytes_to_write = sizeof(wzaes->buffercxx . . $ mz_stream_wzaes_s#buffer.); |
| 204 | int32_tcxx . . $ int32_t# total_written = 0; |
| 205 | int32_tcxx . . $ int32_t# written = 0; |
| 206 | |
| 207 | if (size < 0) |
| 208 | return MZ_PARAM_ERRORcxx . . $ `mz.h:31:9`!; |
| 209 | |
| 210 | do { |
| 211 | if (bytes_to_write > (size - total_written)) |
| 212 | bytes_to_write = (size - total_written); |
| 213 | |
| 214 | memcpycxx . . $ memcpy(cc817cb175f282d).(wzaes->buffercxx . . $ mz_stream_wzaes_s#buffer., buf_ptr, bytes_to_write); |
| 215 | buf_ptr += bytes_to_write; |
| 216 | |
| 217 | mz_stream_wzaes_ctr_encryptcxx . . $ mz_stream_wzaes_ctr_encrypt(78b1a2a92e9cffd0).(stream, (uint8_tcxx . . $ uint8_t# *)wzaes->buffercxx . . $ mz_stream_wzaes_s#buffer., bytes_to_write); |
| 218 | mz_crypt_hmac_updatecxx . . $ mz_crypt_hmac_update(91e54fd90adbb21).(wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac., wzaes->buffercxx . . $ mz_stream_wzaes_s#buffer., bytes_to_write); |
| 219 | |
| 220 | written = mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., wzaes->buffercxx . . $ mz_stream_wzaes_s#buffer., bytes_to_write); |
| 221 | if (written < 0) |
| 222 | return written; |
| 223 | |
| 224 | total_written += written; |
| 225 | } while (total_written < size && written > 0); |
| 226 | |
| 227 | wzaes->total_outcxx . . $ mz_stream_wzaes_s#total_out. += total_written; |
| 228 | return total_written; |
| 229 | } |
| 230 | |
| 231 | int64_tcxx . . $ int64_t# mz_stream_wzaes_tellcxx . . $ mz_stream_wzaes_tell(72c1818a5177f981).(void *stream) { |
| 232 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 233 | return mz_stream_tellcxx . . $ mz_stream_tell(72c1818a5177f981).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base.); |
| 234 | } |
| 235 | |
| 236 | int32_tcxx . . $ int32_t# mz_stream_wzaes_seekcxx . . $ mz_stream_wzaes_seek(8bc0ff128761c75d).(void *stream, int64_tcxx . . $ int64_t# offset, int32_tcxx . . $ int32_t# origin) { |
| 237 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 238 | return mz_stream_seekcxx . . $ mz_stream_seek(8bc0ff128761c75d).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., offset, origin); |
| 239 | } |
| 240 | |
| 241 | int32_tcxx . . $ int32_t# mz_stream_wzaes_closecxx . . $ mz_stream_wzaes_close(dedf1e9b1c614a07).(void *stream) { |
| 242 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 243 | uint8_tcxx . . $ uint8_t# expected_hash[MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!]; |
| 244 | uint8_tcxx . . $ uint8_t# computed_hash[MZ_HASH_SHA1_SIZEcxx . . $ `mz.h:128:9`!]; |
| 245 | |
| 246 | mz_crypt_hmac_endcxx . . $ mz_crypt_hmac_end(78b1a2a92e9cffd0).(wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac., computed_hash, sizeof(computed_hash)); |
| 247 | |
| 248 | if (wzaes->modecxx . . $ mz_stream_wzaes_s#mode. & MZ_OPEN_MODE_WRITEcxx . . $ `mz.h:51:9`!) { |
| 249 | if (mz_stream_writecxx . . $ mz_stream_write(91e54fd90adbb21).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., computed_hash, MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!) != MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!) |
| 250 | return MZ_WRITE_ERRORcxx . . $ `mz.h:45:9`!; |
| 251 | |
| 252 | wzaes->total_outcxx . . $ mz_stream_wzaes_s#total_out. += MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!; |
| 253 | } else if (wzaes->modecxx . . $ mz_stream_wzaes_s#mode. & MZ_OPEN_MODE_READcxx . . $ `mz.h:50:9`!) { |
| 254 | if (mz_stream_readcxx . . $ mz_stream_read(8bc41909eac9e5d8).(wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..basecxx . . $ mz_stream_s#base., expected_hash, MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!) != MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!) |
| 255 | return MZ_READ_ERRORcxx . . $ `mz.h:44:9`!; |
| 256 | |
| 257 | wzaes->total_incxx . . $ mz_stream_wzaes_s#total_in. += MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!; |
| 258 | |
| 259 | /* If entire entry was not read this will fail */ |
| 260 | if (memcmpcxx . . $ memcmp(36f949851efa3055).(computed_hash, expected_hash, MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!) != 0) |
| 261 | return MZ_CRC_ERRORcxx . . $ `mz.h:34:9`!; |
| 262 | } |
| 263 | |
| 264 | wzaes->initializedcxx . . $ mz_stream_wzaes_s#initialized. = 0; |
| 265 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 266 | } |
| 267 | |
| 268 | int32_tcxx . . $ int32_t# mz_stream_wzaes_errorcxx . . $ mz_stream_wzaes_error(dedf1e9b1c614a07).(void *stream) { |
| 269 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 270 | return wzaes->errorcxx . . $ mz_stream_wzaes_s#error.; |
| 271 | } |
| 272 | |
| 273 | void mz_stream_wzaes_set_passwordcxx . . $ mz_stream_wzaes_set_password(e7c9eaecdb7c5ce7).(void *stream, const char *password) { |
| 274 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 275 | wzaes->passwordcxx . . $ mz_stream_wzaes_s#password. = password; |
| 276 | } |
| 277 | |
| 278 | void mz_stream_wzaes_set_strengthcxx . . $ mz_stream_wzaes_set_strength(5b3d32ff749dfd74).(void *stream, uint8_tcxx . . $ uint8_t# strength) { |
| 279 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 280 | wzaes->strengthcxx . . $ mz_stream_wzaes_s#strength. = strength; |
| 281 | } |
| 282 | |
| 283 | int32_tcxx . . $ int32_t# mz_stream_wzaes_get_prop_int64cxx . . $ mz_stream_wzaes_get_prop_int64(280df70541557ec8).(void *stream, int32_tcxx . . $ int32_t# prop, int64_tcxx . . $ int64_t# *value) { |
| 284 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 285 | switch (prop) { |
| 286 | case MZ_STREAM_PROP_TOTAL_INcxx . . $ `mz_strm.h:20:9`!: |
| 287 | *value = wzaes->total_incxx . . $ mz_stream_wzaes_s#total_in.; |
| 288 | break; |
| 289 | case MZ_STREAM_PROP_TOTAL_OUTcxx . . $ `mz_strm.h:22:9`!: |
| 290 | *value = wzaes->total_outcxx . . $ mz_stream_wzaes_s#total_out.; |
| 291 | break; |
| 292 | case MZ_STREAM_PROP_TOTAL_IN_MAXcxx . . $ `mz_strm.h:21:9`!: |
| 293 | *value = wzaes->max_total_incxx . . $ mz_stream_wzaes_s#max_total_in.; |
| 294 | break; |
| 295 | case MZ_STREAM_PROP_HEADER_SIZEcxx . . $ `mz_strm.h:24:9`!: |
| 296 | *value = MZ_AES_SALT_LENGTHcxx . . $ `mz_strm_wzaes.c:21:9`!((int64_t)wzaes->strength) + MZ_AES_PW_VERIFY_SIZEcxx . . $ `mz_strm_wzaes.c:24:9`!; |
| 297 | break; |
| 298 | case MZ_STREAM_PROP_FOOTER_SIZEcxx . . $ `mz_strm.h:25:9`!: |
| 299 | *value = MZ_AES_AUTHCODE_SIZEcxx . . $ `mz_strm_wzaes.c:25:9`!; |
| 300 | break; |
| 301 | default: |
| 302 | return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!; |
| 303 | } |
| 304 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 305 | } |
| 306 | |
| 307 | int32_tcxx . . $ int32_t# mz_stream_wzaes_set_prop_int64cxx . . $ mz_stream_wzaes_set_prop_int64(5f4b2ff0df22ef2b).(void *stream, int32_tcxx . . $ int32_t# prop, int64_tcxx . . $ int64_t# value) { |
| 308 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)stream; |
| 309 | switch (prop) { |
| 310 | case MZ_STREAM_PROP_TOTAL_IN_MAXcxx . . $ `mz_strm.h:21:9`!: |
| 311 | wzaes->max_total_incxx . . $ mz_stream_wzaes_s#max_total_in. = value; |
| 312 | break; |
| 313 | default: |
| 314 | return MZ_EXIST_ERRORcxx . . $ `mz.h:36:9`!; |
| 315 | } |
| 316 | return MZ_OKcxx . . $ `mz.h:21:9`!; |
| 317 | } |
| 318 | |
| 319 | void *mz_stream_wzaes_createcxx . . $ mz_stream_wzaes_create(50c7df7de5344ebb).(void) { |
| 320 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(mz_stream_wzaescxx . . $ mz_stream_wzaes#)); |
| 321 | if (wzaes) { |
| 322 | wzaes->streamcxx . . $ mz_stream_wzaes_s#stream..vtblcxx . . $ mz_stream_s#vtbl. = &mz_stream_wzaes_vtblcxx . . $ mz_stream_wzaes_vtbl.; |
| 323 | wzaes->strengthcxx . . $ mz_stream_wzaes_s#strength. = MZ_AES_STRENGTH_256cxx . . $ `mz.h:119:9`!; |
| 324 | |
| 325 | wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac. = mz_crypt_hmac_createcxx . . $ mz_crypt_hmac_create(50c7df7de5344ebb).(); |
| 326 | if (!wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac.) { |
| 327 | freecxx . . $ free(5d22bdacc48458e8).(wzaes); |
| 328 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 329 | } |
| 330 | wzaes->aescxx . . $ mz_stream_wzaes_s#aes. = mz_crypt_aes_createcxx . . $ mz_crypt_aes_create(50c7df7de5344ebb).(); |
| 331 | if (!wzaes->aescxx . . $ mz_stream_wzaes_s#aes.) { |
| 332 | mz_crypt_hmac_deletecxx . . $ mz_crypt_hmac_delete(539e082cf00e1f43).(&wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac.); |
| 333 | freecxx . . $ free(5d22bdacc48458e8).(wzaes); |
| 334 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 335 | } |
| 336 | } |
| 337 | return wzaes; |
| 338 | } |
| 339 | |
| 340 | void mz_stream_wzaes_deletecxx . . $ mz_stream_wzaes_delete(539e082cf00e1f43).(void **stream) { |
| 341 | mz_stream_wzaescxx . . $ mz_stream_wzaes# *wzaes = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 342 | if (!stream) |
| 343 | return; |
| 344 | wzaes = (mz_stream_wzaescxx . . $ mz_stream_wzaes# *)*stream; |
| 345 | if (wzaes) { |
| 346 | mz_crypt_aes_deletecxx . . $ mz_crypt_aes_delete(539e082cf00e1f43).(&wzaes->aescxx . . $ mz_stream_wzaes_s#aes.); |
| 347 | mz_crypt_hmac_deletecxx . . $ mz_crypt_hmac_delete(539e082cf00e1f43).(&wzaes->hmaccxx . . $ mz_stream_wzaes_s#hmac.); |
| 348 | freecxx . . $ free(5d22bdacc48458e8).(wzaes); |
| 349 | } |
| 350 | *stream = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 351 | } |
| 352 | |
| 353 | void *mz_stream_wzaes_get_interfacecxx . . $ mz_stream_wzaes_get_interface(50c7df7de5344ebb).(void) { |
| 354 | return (void *)&mz_stream_wzaes_vtblcxx . . $ mz_stream_wzaes_vtbl.; |
| 355 | } |