MagickCore  7.1.0
cipher.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % CCCC IIIII PPPP H H EEEEE RRRR %
6 % C I P P H H E R R %
7 % C I PPPP HHHHH EEE RRRR %
8 % C I P H H E R R %
9 % CCCC IIIII P H H EEEEE R R %
10 % %
11 % %
12 % MagickCore Cipher Methods %
13 % %
14 % Software Design %
15 % Cristy %
16 % March 2003 %
17 % %
18 % %
19 % Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
21 % %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
24 % %
25 % https://imagemagick.org/script/license.php %
26 % %
27 % Unless required by applicable law or agreed to in writing, software %
28 % distributed under the License is distributed on an "AS IS" BASIS, %
29 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30 % See the License for the specific language governing permissions and %
31 % limitations under the License. %
32 % %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 %
35 %
36 */
37 
38 /*
39  Include declarations.
40 */
41 #include "MagickCore/studio.h"
42 #include "MagickCore/cache.h"
43 #include "MagickCore/cipher.h"
44 #include "MagickCore/exception.h"
46 #include "MagickCore/image.h"
48 #include "MagickCore/linked-list.h"
49 #include "MagickCore/list.h"
50 #include "MagickCore/memory_.h"
52 #include "MagickCore/monitor.h"
54 #include "MagickCore/property.h"
56 #include "MagickCore/registry.h"
57 #include "MagickCore/semaphore.h"
59 #include "MagickCore/splay-tree.h"
60 #include "MagickCore/statistic.h"
61 #include "MagickCore/string_.h"
62 
63 #if defined(MAGICKCORE_CIPHER_SUPPORT)
64 /*
65  Define declarations.
66 */
67 #define AESBlocksize 16
68 
69 /*
70  Typedef declarations.
71 */
72 typedef struct _AESInfo
73 {
75  *key;
76 
77  unsigned int
78  blocksize,
79  *encipher_key,
80  *decipher_key;
81 
82  ssize_t
83  rounds,
84  timestamp;
85 
86  size_t
87  signature;
88 } AESInfo;
89 
90 /*
91  Global declarations.
92 */
93 static unsigned char
94  InverseLog[256] =
95  {
96  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248,
97  19, 53, 95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10,
98  30, 34, 102, 170, 229, 52, 92, 228, 55, 89, 235, 38, 106, 190,
99  217, 112, 144, 171, 230, 49, 83, 245, 4, 12, 20, 60, 68, 204,
100  79, 209, 104, 184, 211, 110, 178, 205, 76, 212, 103, 169, 224, 59,
101  77, 215, 98, 166, 241, 8, 24, 40, 120, 136, 131, 158, 185, 208,
102  107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154, 181, 196,
103  87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
104  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32,
105  96, 160, 251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86,
106  250, 21, 63, 65, 195, 94, 226, 61, 71, 201, 64, 192, 91, 237,
107  44, 116, 156, 191, 218, 117, 159, 186, 213, 100, 172, 239, 42, 126,
108  130, 157, 188, 223, 122, 142, 137, 128, 155, 182, 193, 88, 232, 35,
109  101, 175, 234, 37, 111, 177, 200, 67, 197, 84, 252, 31, 33, 99,
110  165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202, 69, 207,
111  74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
112  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242,
113  13, 23, 57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180,
114  199, 82, 246, 1
115  },
116  Log[256] =
117  {
118  0, 0, 25, 1, 50, 2, 26, 198, 75, 199, 27, 104, 51, 238,
119  223, 3, 100, 4, 224, 14, 52, 141, 129, 239, 76, 113, 8, 200,
120  248, 105, 28, 193, 125, 194, 29, 181, 249, 185, 39, 106, 77, 228,
121  166, 114, 154, 201, 9, 120, 101, 47, 138, 5, 33, 15, 225, 36,
122  18, 240, 130, 69, 53, 147, 218, 142, 150, 143, 219, 189, 54, 208,
123  206, 148, 19, 92, 210, 241, 64, 70, 131, 56, 102, 221, 253, 48,
124  191, 6, 139, 98, 179, 37, 226, 152, 34, 136, 145, 16, 126, 110,
125  72, 195, 163, 182, 30, 66, 58, 107, 40, 84, 250, 133, 61, 186,
126  43, 121, 10, 21, 155, 159, 94, 202, 78, 212, 172, 229, 243, 115,
127  167, 87, 175, 88, 168, 80, 244, 234, 214, 116, 79, 174, 233, 213,
128  231, 230, 173, 232, 44, 215, 117, 122, 235, 22, 11, 245, 89, 203,
129  95, 176, 156, 169, 81, 160, 127, 12, 246, 111, 23, 196, 73, 236,
130  216, 67, 31, 45, 164, 118, 123, 183, 204, 187, 62, 90, 251, 96,
131  177, 134, 59, 82, 161, 108, 170, 85, 41, 157, 151, 178, 135, 144,
132  97, 190, 220, 252, 188, 149, 207, 205, 55, 63, 91, 209, 83, 57,
133  132, 60, 65, 162, 109, 71, 20, 42, 158, 93, 86, 242, 211, 171,
134  68, 17, 146, 217, 35, 32, 46, 137, 180, 124, 184, 38, 119, 153,
135  227, 165, 103, 74, 237, 222, 197, 49, 254, 24, 13, 99, 140, 128,
136  192, 247, 112, 7,
137  },
138  SBox[256] =
139  {
140  99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215,
141  171, 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175,
142  156, 164, 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165,
143  229, 241, 113, 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154,
144  7, 18, 128, 226, 235, 39, 178, 117, 9, 131, 44, 26, 27, 110,
145  90, 160, 82, 59, 214, 179, 41, 227, 47, 132, 83, 209, 0, 237,
146  32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207, 208, 239,
147  170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168,
148  81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255,
149  243, 210, 205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61,
150  100, 93, 25, 115, 96, 129, 79, 220, 34, 42, 144, 136, 70, 238,
151  184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73, 6, 36, 92,
152  194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109, 141, 213,
153  78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37, 46,
154  28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62,
155  181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158,
156  225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85,
157  40, 223, 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15,
158  176, 84, 187, 22
159  };
160 
161 /*
162  Forward declarations.
163 */
164 static AESInfo
165  *DestroyAESInfo(AESInfo *);
166 
167 static void
168  EncipherAESBlock(AESInfo *,const unsigned char *,unsigned char *),
169  SetAESKey(AESInfo *,const StringInfo *);
170 
171 /*
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 % %
174 % %
175 % %
176 % A c q u i r e A E S I n f o %
177 % %
178 % %
179 % %
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 %
182 % AcquireAESInfo() allocate the AESInfo structure.
183 %
184 % The format of the AcquireAESInfo method is:
185 %
186 % AESInfo *AcquireAESInfo(void)
187 %
188 */
189 static AESInfo *AcquireAESInfo(void)
190 {
191  AESInfo
192  *aes_info;
193 
194  aes_info=(AESInfo *) AcquireCriticalMemory(sizeof(*aes_info));
195  (void) memset(aes_info,0,sizeof(*aes_info));
196  aes_info->blocksize=AESBlocksize;
197  aes_info->key=AcquireStringInfo(32);
198  aes_info->encipher_key=(unsigned int *) AcquireQuantumMemory(60UL,sizeof(
199  *aes_info->encipher_key));
200  aes_info->decipher_key=(unsigned int *) AcquireQuantumMemory(60UL,sizeof(
201  *aes_info->decipher_key));
202  if ((aes_info->key == (StringInfo *) NULL) ||
203  (aes_info->encipher_key == (unsigned int *) NULL) ||
204  (aes_info->decipher_key == (unsigned int *) NULL))
205  ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
206  aes_info->timestamp=(ssize_t) time(0);
207  aes_info->signature=MagickCoreSignature;
208  return(aes_info);
209 }
210 
211 /*
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 % %
214 % %
215 % %
216 % D e s t r o y A E S I n f o %
217 % %
218 % %
219 % %
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 %
222 % DestroyAESInfo() zeros memory associated with the AESInfo structure.
223 %
224 % The format of the DestroyAESInfo method is:
225 %
226 % AESInfo *DestroyAESInfo(AESInfo *aes_info)
227 %
228 % A description of each parameter follows:
229 %
230 % o aes_info: the cipher context.
231 %
232 */
233 static AESInfo *DestroyAESInfo(AESInfo *aes_info)
234 {
235  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
236  assert(aes_info != (AESInfo *) NULL);
237  assert(aes_info->signature == MagickCoreSignature);
238  if (aes_info->decipher_key != (unsigned int *) NULL)
239  aes_info->decipher_key=(unsigned int *) RelinquishMagickMemory(
240  aes_info->decipher_key);
241  if (aes_info->encipher_key != (unsigned int *) NULL)
242  aes_info->encipher_key=(unsigned int *) RelinquishMagickMemory(
243  aes_info->encipher_key);
244  if (aes_info->key != (StringInfo *) NULL)
245  aes_info->key=DestroyStringInfo(aes_info->key);
246  aes_info->signature=(~MagickCoreSignature);
247  aes_info=(AESInfo *) RelinquishMagickMemory(aes_info);
248  return(aes_info);
249 }
250 
251 /*
252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % %
254 % %
255 % %
256 % E n c i p h e r A E S B l o c k %
257 % %
258 % %
259 % %
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 %
262 % EncipherAESBlock() enciphers a single block of plaintext to produce a block
263 % of ciphertext.
264 %
265 % The format of the EncipherAESBlock method is:
266 %
267 % void EncipherAES(AESInfo *aes_info,const unsigned char *plaintext,
268 % unsigned char *ciphertext)
269 %
270 % A description of each parameter follows:
271 %
272 % o aes_info: the cipher context.
273 %
274 % o plaintext: the plain text.
275 %
276 % o ciphertext: the cipher text.
277 %
278 */
279 
280 static inline void AddRoundKey(const unsigned int *ciphertext,
281  const unsigned int *key,unsigned int *plaintext)
282 {
283  ssize_t
284  i;
285 
286  /*
287  Xor corresponding text input and round key input bytes.
288  */
289  for (i=0; i < 4; i++)
290  plaintext[i]=key[i] ^ ciphertext[i];
291 }
292 
293 static inline unsigned int ByteMultiply(const unsigned char alpha,
294  const unsigned char beta)
295 {
296  /*
297  Byte multiply two elements of GF(2^m) (mix columns and inverse mix columns).
298  */
299  if ((alpha == 0) || (beta == 0))
300  return(0);
301  return((unsigned int) InverseLog[(Log[alpha]+Log[beta]) % 0xff]);
302 }
303 
304 static inline unsigned int ByteSubTransform(unsigned int x,
305  unsigned char *s_box)
306 {
307  unsigned int
308  key;
309 
310  /*
311  Non-linear layer resists differential and linear cryptoanalysis attacks.
312  */
313  key=((unsigned int) s_box[x & 0xff]) |
314  ((unsigned int) s_box[(x >> 8) & 0xff] << 8) |
315  ((unsigned int) s_box[(x >> 16) & 0xff] << 16) |
316  ((unsigned int) s_box[(x >> 24) & 0xff] << 24);
317  return(key);
318 }
319 
320 static void FinalizeRoundKey(const unsigned int *ciphertext,
321  const unsigned int *key,unsigned char *plaintext)
322 {
323  unsigned char
324  *p;
325 
326  unsigned int
327  i,
328  j;
329 
330  unsigned int
331  value;
332 
333  /*
334  The round key is XORed with the result of the mix-column transformation.
335  */
336  p=plaintext;
337  for (i=0; i < 4; i++)
338  {
339  value=ciphertext[i] ^ key[i];
340  for (j=0; j < 4; j++)
341  *p++=(unsigned char) ((value >> (8*j)) & 0xff);
342  }
343  /*
344  Reset registers.
345  */
346  value=0;
347 }
348 
349 static void InitializeRoundKey(const unsigned char *ciphertext,
350  const unsigned int *key,unsigned int *plaintext)
351 {
352  const unsigned char
353  *p;
354 
355  unsigned int
356  i,
357  j;
358 
359  unsigned int
360  value;
361 
362  p=ciphertext;
363  for (i=0; i < 4; i++)
364  {
365  value=0;
366  for (j=0; j < 4; j++)
367  value|=((unsigned int) *p++ << (8*j));
368  plaintext[i]=key[i] ^ value;
369  }
370  /*
371  Reset registers.
372  */
373  value=0;
374 }
375 
376 static inline unsigned int RotateLeft(const unsigned int x)
377 {
378  return(((x << 8) | ((x >> 24) & 0xff)));
379 }
380 
381 static void EncipherAESBlock(AESInfo *aes_info,const unsigned char *plaintext,
382  unsigned char *ciphertext)
383 {
384  ssize_t
385  i,
386  j;
387 
388  static int
389  map[4][4] =
390  {
391  { 0, 1, 2, 3 },
392  { 1, 2, 3, 0 },
393  { 2, 3, 0, 1 },
394  { 3, 0, 1, 2 }
395  };
396 
397  static unsigned int
398  D[] =
399  {
400  0xa56363c6U, 0x847c7cf8U, 0x997777eeU, 0x8d7b7bf6U, 0x0df2f2ffU,
401  0xbd6b6bd6U, 0xb16f6fdeU, 0x54c5c591U, 0x50303060U, 0x03010102U,
402  0xa96767ceU, 0x7d2b2b56U, 0x19fefee7U, 0x62d7d7b5U, 0xe6abab4dU,
403  0x9a7676ecU, 0x45caca8fU, 0x9d82821fU, 0x40c9c989U, 0x877d7dfaU,
404  0x15fafaefU, 0xeb5959b2U, 0xc947478eU, 0x0bf0f0fbU, 0xecadad41U,
405  0x67d4d4b3U, 0xfda2a25fU, 0xeaafaf45U, 0xbf9c9c23U, 0xf7a4a453U,
406  0x967272e4U, 0x5bc0c09bU, 0xc2b7b775U, 0x1cfdfde1U, 0xae93933dU,
407  0x6a26264cU, 0x5a36366cU, 0x413f3f7eU, 0x02f7f7f5U, 0x4fcccc83U,
408  0x5c343468U, 0xf4a5a551U, 0x34e5e5d1U, 0x08f1f1f9U, 0x937171e2U,
409  0x73d8d8abU, 0x53313162U, 0x3f15152aU, 0x0c040408U, 0x52c7c795U,
410  0x65232346U, 0x5ec3c39dU, 0x28181830U, 0xa1969637U, 0x0f05050aU,
411  0xb59a9a2fU, 0x0907070eU, 0x36121224U, 0x9b80801bU, 0x3de2e2dfU,
412  0x26ebebcdU, 0x6927274eU, 0xcdb2b27fU, 0x9f7575eaU, 0x1b090912U,
413  0x9e83831dU, 0x742c2c58U, 0x2e1a1a34U, 0x2d1b1b36U, 0xb26e6edcU,
414  0xee5a5ab4U, 0xfba0a05bU, 0xf65252a4U, 0x4d3b3b76U, 0x61d6d6b7U,
415  0xceb3b37dU, 0x7b292952U, 0x3ee3e3ddU, 0x712f2f5eU, 0x97848413U,
416  0xf55353a6U, 0x68d1d1b9U, 0x00000000U, 0x2cededc1U, 0x60202040U,
417  0x1ffcfce3U, 0xc8b1b179U, 0xed5b5bb6U, 0xbe6a6ad4U, 0x46cbcb8dU,
418  0xd9bebe67U, 0x4b393972U, 0xde4a4a94U, 0xd44c4c98U, 0xe85858b0U,
419  0x4acfcf85U, 0x6bd0d0bbU, 0x2aefefc5U, 0xe5aaaa4fU, 0x16fbfbedU,
420  0xc5434386U, 0xd74d4d9aU, 0x55333366U, 0x94858511U, 0xcf45458aU,
421  0x10f9f9e9U, 0x06020204U, 0x817f7ffeU, 0xf05050a0U, 0x443c3c78U,
422  0xba9f9f25U, 0xe3a8a84bU, 0xf35151a2U, 0xfea3a35dU, 0xc0404080U,
423  0x8a8f8f05U, 0xad92923fU, 0xbc9d9d21U, 0x48383870U, 0x04f5f5f1U,
424  0xdfbcbc63U, 0xc1b6b677U, 0x75dadaafU, 0x63212142U, 0x30101020U,
425  0x1affffe5U, 0x0ef3f3fdU, 0x6dd2d2bfU, 0x4ccdcd81U, 0x140c0c18U,
426  0x35131326U, 0x2fececc3U, 0xe15f5fbeU, 0xa2979735U, 0xcc444488U,
427  0x3917172eU, 0x57c4c493U, 0xf2a7a755U, 0x827e7efcU, 0x473d3d7aU,
428  0xac6464c8U, 0xe75d5dbaU, 0x2b191932U, 0x957373e6U, 0xa06060c0U,
429  0x98818119U, 0xd14f4f9eU, 0x7fdcdca3U, 0x66222244U, 0x7e2a2a54U,
430  0xab90903bU, 0x8388880bU, 0xca46468cU, 0x29eeeec7U, 0xd3b8b86bU,
431  0x3c141428U, 0x79dedea7U, 0xe25e5ebcU, 0x1d0b0b16U, 0x76dbdbadU,
432  0x3be0e0dbU, 0x56323264U, 0x4e3a3a74U, 0x1e0a0a14U, 0xdb494992U,
433  0x0a06060cU, 0x6c242448U, 0xe45c5cb8U, 0x5dc2c29fU, 0x6ed3d3bdU,
434  0xefacac43U, 0xa66262c4U, 0xa8919139U, 0xa4959531U, 0x37e4e4d3U,
435  0x8b7979f2U, 0x32e7e7d5U, 0x43c8c88bU, 0x5937376eU, 0xb76d6ddaU,
436  0x8c8d8d01U, 0x64d5d5b1U, 0xd24e4e9cU, 0xe0a9a949U, 0xb46c6cd8U,
437  0xfa5656acU, 0x07f4f4f3U, 0x25eaeacfU, 0xaf6565caU, 0x8e7a7af4U,
438  0xe9aeae47U, 0x18080810U, 0xd5baba6fU, 0x887878f0U, 0x6f25254aU,
439  0x722e2e5cU, 0x241c1c38U, 0xf1a6a657U, 0xc7b4b473U, 0x51c6c697U,
440  0x23e8e8cbU, 0x7cdddda1U, 0x9c7474e8U, 0x211f1f3eU, 0xdd4b4b96U,
441  0xdcbdbd61U, 0x868b8b0dU, 0x858a8a0fU, 0x907070e0U, 0x423e3e7cU,
442  0xc4b5b571U, 0xaa6666ccU, 0xd8484890U, 0x05030306U, 0x01f6f6f7U,
443  0x120e0e1cU, 0xa36161c2U, 0x5f35356aU, 0xf95757aeU, 0xd0b9b969U,
444  0x91868617U, 0x58c1c199U, 0x271d1d3aU, 0xb99e9e27U, 0x38e1e1d9U,
445  0x13f8f8ebU, 0xb398982bU, 0x33111122U, 0xbb6969d2U, 0x70d9d9a9U,
446  0x898e8e07U, 0xa7949433U, 0xb69b9b2dU, 0x221e1e3cU, 0x92878715U,
447  0x20e9e9c9U, 0x49cece87U, 0xff5555aaU, 0x78282850U, 0x7adfdfa5U,
448  0x8f8c8c03U, 0xf8a1a159U, 0x80898909U, 0x170d0d1aU, 0xdabfbf65U,
449  0x31e6e6d7U, 0xc6424284U, 0xb86868d0U, 0xc3414182U, 0xb0999929U,
450  0x772d2d5aU, 0x110f0f1eU, 0xcbb0b07bU, 0xfc5454a8U, 0xd6bbbb6dU,
451  0x3a16162cU
452  };
453 
454  unsigned int
455  alpha,
456  key[4],
457  text[4];
458 
459  /*
460  Encipher one block.
461  */
462  (void) memset(text,0,sizeof(text));
463  InitializeRoundKey(plaintext,aes_info->encipher_key,text);
464  for (i=1; i < aes_info->rounds; i++)
465  {
466  /*
467  Linear mixing step: cause diffusion of the bits over multiple rounds.
468  */
469  for (j=0; j < 4; j++)
470  key[j]=D[text[j] & 0xff] ^
471  RotateLeft(D[(text[map[1][j]] >> 8) & 0xff] ^
472  RotateLeft(D[(text[map[2][j]] >> 16) & 0xff] ^
473  RotateLeft(D[(text[map[3][j]] >> 24) & 0xff])));
474  AddRoundKey(key,aes_info->encipher_key+4*i,text);
475  }
476  for (i=0; i < 4; i++)
477  {
478  alpha=(text[i] & 0x000000ff) | ((text[map[1][i]]) & 0x0000ff00) |
479  ((text[map[2][i]]) & 0x00ff0000) | ((text[map[3][i]]) & 0xff000000);
480  key[i]=ByteSubTransform(alpha,SBox);
481  }
482  FinalizeRoundKey(key,aes_info->encipher_key+4*aes_info->rounds,ciphertext);
483  /*
484  Reset registers.
485  */
486  alpha=0;
487  (void) ResetMagickMemory(key,0,sizeof(key));
488  (void) ResetMagickMemory(text,0,sizeof(text));
489 }
490 
491 /*
492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
493 % %
494 % %
495 % %
496 % P a s s k e y D e c i p h e r I m a g e %
497 % %
498 % %
499 % %
500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
501 %
502 % PasskeyDecipherImage() converts cipher pixels to plain pixels.
503 %
504 % The format of the PasskeyDecipherImage method is:
505 %
506 % MagickBooleanType PasskeyDecipherImage(Image *image,
507 % const StringInfo *passkey,ExceptionInfo *exception)
508 % MagickBooleanType DecipherImage(Image *image,const char *passphrase,
509 % ExceptionInfo *exception)
510 %
511 % A description of each parameter follows:
512 %
513 % o image: the image.
514 %
515 % o passphrase: decipher cipher pixels with this passphrase.
516 %
517 % o passkey: decrypt cipher pixels with this passkey.
518 %
519 % o exception: return any errors or warnings in this structure.
520 %
521 */
522 
523 static inline void IncrementCipherNonce(const size_t length,
524  unsigned char *nonce)
525 {
526  ssize_t
527  i;
528 
529  for (i=(ssize_t) (length-1); i >= 0; i--)
530  {
531  nonce[i]++;
532  if (nonce[i] != 0)
533  return;
534  }
535  ThrowFatalException(ResourceLimitFatalError,"Sequence wrap error `%s'");
536 }
537 
539  const char *passphrase,ExceptionInfo *exception)
540 {
542  status;
543 
544  StringInfo
545  *passkey;
546 
547  if (passphrase == (const char *) NULL)
548  return(MagickTrue);
549  passkey=StringToStringInfo(passphrase);
550  if (passkey == (StringInfo *) NULL)
551  return(MagickFalse);
552  status=PasskeyDecipherImage(image,passkey,exception);
553  passkey=DestroyStringInfo(passkey);
554  return(status);
555 }
556 
558  const StringInfo *passkey,ExceptionInfo *exception)
559 {
560 #define DecipherImageTag "Decipher/Image "
561 
562  AESInfo
563  *aes_info;
564 
565  CacheView
566  *image_view;
567 
568  const unsigned char
569  *digest;
570 
572  proceed;
573 
575  extent;
576 
578  *quantum_info;
579 
581  quantum_type;
582 
584  *signature_info;
585 
586  unsigned char
587  *p;
588 
589  size_t
590  length;
591 
592  ssize_t
593  y;
594 
595  StringInfo
596  *key,
597  *nonce;
598 
599  unsigned char
600  input_block[AESBlocksize],
601  output_block[AESBlocksize],
602  *pixels;
603 
604  /*
605  Generate decipher key and nonce.
606  */
607  assert(image != (Image *) NULL);
608  assert(image->signature == MagickCoreSignature);
609  if (image->debug != MagickFalse)
610  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
611  assert(exception != (ExceptionInfo *) NULL);
612  assert(exception->signature == MagickCoreSignature);
613  if (passkey == (const StringInfo *) NULL)
614  return(MagickTrue);
615  aes_info=AcquireAESInfo();
616  key=CloneStringInfo(passkey);
617  if (key == (StringInfo *) NULL)
618  {
619  aes_info=DestroyAESInfo(aes_info);
620  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
621  image->filename);
622  }
623  nonce=SplitStringInfo(key,GetStringInfoLength(key)/2);
624  if (nonce == (StringInfo *) NULL)
625  {
626  key=DestroyStringInfo(key);
627  aes_info=DestroyAESInfo(aes_info);
628  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
629  image->filename);
630  }
631  SetAESKey(aes_info,key);
632  key=DestroyStringInfo(key);
633  signature_info=AcquireSignatureInfo();
634  UpdateSignature(signature_info,nonce);
635  extent=(MagickSizeType) image->columns*image->rows;
636  SetStringInfoLength(nonce,sizeof(extent));
637  SetStringInfoDatum(nonce,(const unsigned char *) &extent);
638  UpdateSignature(signature_info,nonce);
639  nonce=DestroyStringInfo(nonce);
640  FinalizeSignature(signature_info);
641  (void) memset(input_block,0,sizeof(input_block));
642  digest=GetStringInfoDatum(GetSignatureDigest(signature_info));
643  (void) memcpy(input_block,digest,MagickMin(AESBlocksize,
644  GetSignatureDigestsize(signature_info))*sizeof(*input_block));
645  signature_info=DestroySignatureInfo(signature_info);
646  /*
647  Convert cipher pixels to plain pixels.
648  */
649  quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
650  if (quantum_info == (QuantumInfo *) NULL)
651  {
652  aes_info=DestroyAESInfo(aes_info);
653  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
654  image->filename);
655  }
656  quantum_type=GetQuantumType(image,exception);
657  pixels=(unsigned char *) GetQuantumPixels(quantum_info);
658  image_view=AcquireAuthenticCacheView(image,exception);
659  for (y=0; y < (ssize_t) image->rows; y++)
660  {
661  ssize_t
662  i,
663  x;
664 
665  Quantum
666  *magick_restrict q;
667 
668  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
669  if (q == (Quantum *) NULL)
670  break;
671  length=ExportQuantumPixels(image,image_view,quantum_info,quantum_type,
672  pixels,exception);
673  p=pixels;
674  for (x=0; x < (ssize_t) length; x+=AESBlocksize)
675  {
676  (void) memcpy(output_block,input_block,AESBlocksize*
677  sizeof(*output_block));
678  IncrementCipherNonce(AESBlocksize,input_block);
679  EncipherAESBlock(aes_info,output_block,output_block);
680  for (i=0; i < AESBlocksize; i++)
681  p[i]^=output_block[i];
682  p+=AESBlocksize;
683  }
684  (void) memcpy(output_block,input_block,AESBlocksize*
685  sizeof(*output_block));
686  EncipherAESBlock(aes_info,output_block,output_block);
687  for (i=0; x < (ssize_t) length; x++)
688  {
689  p[i]^=output_block[i];
690  i++;
691  }
692  (void) ImportQuantumPixels(image,image_view,quantum_info,quantum_type,
693  pixels,exception);
694  if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
695  break;
696  proceed=SetImageProgress(image,DecipherImageTag,(MagickOffsetType) y,
697  image->rows);
698  if (proceed == MagickFalse)
699  break;
700  }
701  image_view=DestroyCacheView(image_view);
702  (void) DeleteImageProperty(image,"cipher:type");
703  (void) DeleteImageProperty(image,"cipher:mode");
704  (void) DeleteImageProperty(image,"cipher:nonce");
705  image->taint=MagickFalse;
706  /*
707  Free resources.
708  */
709  quantum_info=DestroyQuantumInfo(quantum_info);
710  aes_info=DestroyAESInfo(aes_info);
711  (void) ResetMagickMemory(input_block,0,sizeof(input_block));
712  (void) ResetMagickMemory(output_block,0,sizeof(output_block));
713  return(y == (ssize_t) image->rows ? MagickTrue : MagickFalse);
714 }
715 
716 /*
717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
718 % %
719 % %
720 % %
721 % P a s s k e y E n c i p h e r I m a g e %
722 % %
723 % %
724 % %
725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
726 %
727 % PasskeyEncipherImage() converts pixels to cipher-pixels.
728 %
729 % The format of the PasskeyEncipherImage method is:
730 %
731 % MagickBooleanType PasskeyEncipherImage(Image *image,
732 % const StringInfo *passkey,ExceptionInfo *exception)
733 % MagickBooleanType EncipherImage(Image *image,const char *passphrase,
734 % ExceptionInfo *exception)
735 %
736 % A description of each parameter follows:
737 %
738 % o image: the image.
739 %
740 % o passphrase: encipher pixels with this passphrase.
741 %
742 % o passkey: decrypt cipher pixels with this passkey.
743 %
744 % o exception: return any errors or warnings in this structure.
745 %
746 */
747 
749  const char *passphrase,ExceptionInfo *exception)
750 {
752  status;
753 
754  StringInfo
755  *passkey;
756 
757  if (passphrase == (const char *) NULL)
758  return(MagickTrue);
759  passkey=StringToStringInfo(passphrase);
760  if (passkey == (StringInfo *) NULL)
761  return(MagickFalse);
762  status=PasskeyEncipherImage(image,passkey,exception);
763  passkey=DestroyStringInfo(passkey);
764  return(status);
765 }
766 
768  const StringInfo *passkey,ExceptionInfo *exception)
769 {
770 #define EncipherImageTag "Encipher/Image "
771 
772  AESInfo
773  *aes_info;
774 
775  CacheView
776  *image_view;
777 
778  char
779  *signature;
780 
781  const unsigned char
782  *digest;
783 
785  proceed;
786 
788  extent;
789 
791  *quantum_info;
792 
794  quantum_type;
795 
796  unsigned char
797  *p;
798 
800  *signature_info;
801 
802  size_t
803  length;
804 
805  ssize_t
806  y;
807 
808  StringInfo
809  *key,
810  *nonce;
811 
812  unsigned char
813  input_block[AESBlocksize],
814  output_block[AESBlocksize],
815  *pixels;
816 
817  /*
818  Generate encipher key and nonce.
819  */
820  assert(image != (Image *) NULL);
821  assert(image->signature == MagickCoreSignature);
822  if (image->debug != MagickFalse)
823  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
824  assert(exception != (ExceptionInfo *) NULL);
825  assert(exception->signature == MagickCoreSignature);
826  if (passkey == (const StringInfo *) NULL)
827  return(MagickTrue);
828  if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
829  return(MagickFalse);
830  aes_info=AcquireAESInfo();
831  key=CloneStringInfo(passkey);
832  if (key == (StringInfo *) NULL)
833  {
834  aes_info=DestroyAESInfo(aes_info);
835  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
836  image->filename);
837  }
838  nonce=SplitStringInfo(key,GetStringInfoLength(key)/2);
839  if (nonce == (StringInfo *) NULL)
840  {
841  key=DestroyStringInfo(key);
842  aes_info=DestroyAESInfo(aes_info);
843  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
844  image->filename);
845  }
846  SetAESKey(aes_info,key);
847  key=DestroyStringInfo(key);
848  signature_info=AcquireSignatureInfo();
849  UpdateSignature(signature_info,nonce);
850  extent=(MagickSizeType) image->columns*image->rows;
851  SetStringInfoLength(nonce,sizeof(extent));
852  SetStringInfoDatum(nonce,(const unsigned char *) &extent);
853  UpdateSignature(signature_info,nonce);
854  nonce=DestroyStringInfo(nonce);
855  FinalizeSignature(signature_info);
856  signature=StringInfoToHexString(GetSignatureDigest(signature_info));
857  (void) SetImageProperty(image,"cipher:type","AES",exception);
858  (void) SetImageProperty(image,"cipher:mode","CTR",exception);
859  (void) SetImageProperty(image,"cipher:nonce",signature,exception);
860  signature=DestroyString(signature);
861  (void) memset(input_block,0,sizeof(input_block));
862  digest=GetStringInfoDatum(GetSignatureDigest(signature_info));
863  (void) memcpy(input_block,digest,MagickMin(AESBlocksize,
864  GetSignatureDigestsize(signature_info))*sizeof(*input_block));
865  signature_info=DestroySignatureInfo(signature_info);
866  /*
867  Convert plain pixels to cipher pixels.
868  */
869  quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
870  if (quantum_info == (QuantumInfo *) NULL)
871  {
872  aes_info=DestroyAESInfo(aes_info);
873  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
874  image->filename);
875  }
876  quantum_type=GetQuantumType(image,exception);
877  pixels=(unsigned char *) GetQuantumPixels(quantum_info);
878  image_view=AcquireAuthenticCacheView(image,exception);
879  for (y=0; y < (ssize_t) image->rows; y++)
880  {
881  ssize_t
882  i,
883  x;
884 
885  Quantum
886  *magick_restrict q;
887 
888  q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
889  if (q == (Quantum *) NULL)
890  break;
891  length=ExportQuantumPixels(image,image_view,quantum_info,quantum_type,
892  pixels,exception);
893  p=pixels;
894  for (x=0; x < (ssize_t) length; x+=AESBlocksize)
895  {
896  (void) memcpy(output_block,input_block,AESBlocksize*
897  sizeof(*output_block));
898  IncrementCipherNonce(AESBlocksize,input_block);
899  EncipherAESBlock(aes_info,output_block,output_block);
900  for (i=0; i < AESBlocksize; i++)
901  p[i]^=output_block[i];
902  p+=AESBlocksize;
903  }
904  (void) memcpy(output_block,input_block,AESBlocksize*
905  sizeof(*output_block));
906  EncipherAESBlock(aes_info,output_block,output_block);
907  for (i=0; x < (ssize_t) length; x++)
908  {
909  p[i]^=output_block[i];
910  i++;
911  }
912  (void) ImportQuantumPixels(image,image_view,quantum_info,quantum_type,
913  pixels,exception);
914  if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
915  break;
916  proceed=SetImageProgress(image,EncipherImageTag,(MagickOffsetType) y,
917  image->rows);
918  if (proceed == MagickFalse)
919  break;
920  }
921  image_view=DestroyCacheView(image_view);
922  image->taint=MagickFalse;
923  /*
924  Free resources.
925  */
926  quantum_info=DestroyQuantumInfo(quantum_info);
927  aes_info=DestroyAESInfo(aes_info);
928  (void) ResetMagickMemory(input_block,0,sizeof(input_block));
929  (void) ResetMagickMemory(output_block,0,sizeof(output_block));
930  return(y == (ssize_t) image->rows ? MagickTrue : MagickFalse);
931 }
932 
933 /*
934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
935 % %
936 % %
937 % %
938 % S e t A E S K e y %
939 % %
940 % %
941 % %
942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
943 %
944 % SetAESKey() sets the key for the AES cipher. The key length is specified
945 % in bits. Valid values are 128, 192, or 256 requiring a key buffer length
946 % in bytes of 16, 24, and 32 respectively.
947 %
948 % The format of the SetAESKey method is:
949 %
950 % SetAESKey(AESInfo *aes_info,const StringInfo *key)
951 %
952 % A description of each parameter follows:
953 %
954 % o aes_info: the cipher context.
955 %
956 % o key: the key.
957 %
958 */
959 
960 static inline void InverseAddRoundKey(const unsigned int *alpha,
961  unsigned int *beta)
962 {
963  unsigned int
964  i,
965  j;
966 
967  for (i=0; i < 4; i++)
968  {
969  beta[i]=0;
970  for (j=0; j < 4; j++)
971  beta[i]|=(ByteMultiply(0xe,(alpha[i] >> (8*j)) & 0xff) ^
972  ByteMultiply(0xb,(alpha[i] >> (8*((j+1) % 4))) & 0xff) ^
973  ByteMultiply(0xd,(alpha[i] >> (8*((j+2) % 4))) & 0xff) ^
974  ByteMultiply(0x9,(alpha[i] >> (8*((j+3) % 4))) & 0xff)) << (8*j);
975  }
976 }
977 
978 static inline unsigned int XTime(unsigned char alpha)
979 {
980  unsigned char
981  beta;
982 
983  beta=(unsigned char) ((alpha & 0x80) != 0 ? 0x1b : 0);
984  alpha<<=1;
985  alpha^=beta;
986  return(alpha);
987 }
988 
989 static inline unsigned int RotateRight(const unsigned int x)
990 {
991  return((x >> 8) | ((x & 0xff) << 24));
992 }
993 
994 static void SetAESKey(AESInfo *aes_info,const StringInfo *key)
995 {
996  ssize_t
997  i;
998 
999  ssize_t
1000  bytes,
1001  n;
1002 
1003  unsigned char
1004  *datum;
1005 
1006  unsigned int
1007  alpha,
1008  beta;
1009 
1010  /*
1011  Determine the number of rounds based on the number of bits in key.
1012  */
1013  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1014  assert(aes_info != (AESInfo *) NULL);
1015  assert(aes_info->signature == MagickCoreSignature);
1016  assert(key != (StringInfo *) NULL);
1017  n=4;
1018  aes_info->rounds=10;
1019  if ((8*GetStringInfoLength(key)) >= 256)
1020  {
1021  n=8;
1022  aes_info->rounds=14;
1023  }
1024  else
1025  if ((8*GetStringInfoLength(key)) >= 192)
1026  {
1027  n=6;
1028  aes_info->rounds=12;
1029  }
1030  /*
1031  Generate crypt key.
1032  */
1033  datum=GetStringInfoDatum(aes_info->key);
1034  (void) memset(datum,0,GetStringInfoLength(aes_info->key));
1035  (void) memcpy(datum,GetStringInfoDatum(key),MagickMin(
1036  GetStringInfoLength(key),GetStringInfoLength(aes_info->key)));
1037  for (i=0; i < n; i++)
1038  aes_info->encipher_key[i]=(unsigned int) datum[4*i] |
1039  ((unsigned int) datum[4*i+1] << 8) |
1040  ((unsigned int) datum[4*i+2] << 16) |
1041  ((unsigned int) datum[4*i+3] << 24);
1042  beta=1;
1043  bytes=(AESBlocksize/4)*(aes_info->rounds+1);
1044  for (i=n; i < bytes; i++)
1045  {
1046  alpha=aes_info->encipher_key[i-1];
1047  if ((i % n) == 0)
1048  {
1049  alpha=ByteSubTransform(RotateRight(alpha),SBox) ^ beta;
1050  beta=XTime((unsigned char) (beta & 0xff));
1051  }
1052  else
1053  if ((n > 6) && ((i % n) == 4))
1054  alpha=ByteSubTransform(alpha,SBox);
1055  aes_info->encipher_key[i]=aes_info->encipher_key[i-n] ^ alpha;
1056  }
1057  /*
1058  Generate deciper key (in reverse order).
1059  */
1060  for (i=0; i < 4; i++)
1061  {
1062  aes_info->decipher_key[i]=aes_info->encipher_key[i];
1063  aes_info->decipher_key[bytes-4+i]=aes_info->encipher_key[bytes-4+i];
1064  }
1065  for (i=4; i < (bytes-4); i+=4)
1066  InverseAddRoundKey(aes_info->encipher_key+i,aes_info->decipher_key+i);
1067  /*
1068  Reset registers.
1069  */
1070  datum=GetStringInfoDatum(aes_info->key);
1071  (void) memset(datum,0,GetStringInfoLength(aes_info->key));
1072  alpha=0;
1073  beta=0;
1074 }
1075 #else
1076 
1077 /*
1078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1079 % %
1080 % %
1081 % %
1082 % P a s s k e y D e c i p h e r I m a g e %
1083 % %
1084 % %
1085 % %
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 %
1088 % PasskeyDecipherImage() converts cipher pixels to plain pixels.
1089 %
1090 % The format of the PasskeyDecipherImage method is:
1091 %
1092 % MagickBooleanType PasskeyDecipherImage(Image *image,
1093 % const StringInfo *passkey,ExceptionInfo *exception)
1094 % MagickBooleanType DecipherImage(Image *image,const char *passphrase,
1095 % ExceptionInfo *exception)
1096 %
1097 % A description of each parameter follows:
1098 %
1099 % o image: the image.
1100 %
1101 % o passphrase: decipher cipher pixels with this passphrase.
1102 %
1103 % o passkey: decrypt cipher pixels with this passkey.
1104 %
1105 % o exception: return any errors or warnings in this structure.
1106 %
1107 */
1108 
1110  const char *passphrase,ExceptionInfo *exception)
1111 {
1112  assert(image != (Image *) NULL);
1113  assert(image->signature == MagickCoreSignature);
1114  if (image->debug != MagickFalse)
1115  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1116  assert(exception != (ExceptionInfo *) NULL);
1117  assert(exception->signature == MagickCoreSignature);
1118  (void) passphrase;
1119  ThrowBinaryException(ImageError,"CipherSupportNotEnabled",image->filename);
1120 }
1121 
1123  const StringInfo *passkey,ExceptionInfo *exception)
1124 {
1125  assert(image != (Image *) NULL);
1126  assert(image->signature == MagickCoreSignature);
1127  if (image->debug != MagickFalse)
1128  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1129  assert(exception != (ExceptionInfo *) NULL);
1130  assert(exception->signature == MagickCoreSignature);
1131  (void) passkey;
1132  ThrowBinaryException(ImageError,"CipherSupportNotEnabled",image->filename);
1133 }
1134 
1135 /*
1136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1137 % %
1138 % %
1139 % %
1140 % P a s s k e y E n c i p h e r I m a g e %
1141 % %
1142 % %
1143 % %
1144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1145 %
1146 % PasskeyEncipherImage() converts pixels to cipher-pixels.
1147 %
1148 % The format of the PasskeyEncipherImage method is:
1149 %
1150 % MagickBooleanType PasskeyEncipherImage(Image *image,
1151 % const StringInfo *passkey,ExceptionInfo *exception)
1152 % MagickBooleanType EncipherImage(Image *image,const char *passphrase,
1153 % ExceptionInfo *exception)
1154 %
1155 % A description of each parameter follows:
1156 %
1157 % o passphrase: decipher cipher pixels with this passphrase.
1158 %
1159 % o passkey: decrypt cipher pixels with this passkey.
1160 %
1161 % o exception: return any errors or warnings in this structure.
1162 %
1163 */
1164 
1166  const char *passphrase,ExceptionInfo *exception)
1167 {
1168  assert(image != (Image *) NULL);
1169  assert(image->signature == MagickCoreSignature);
1170  if (image->debug != MagickFalse)
1171  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1172  assert(exception != (ExceptionInfo *) NULL);
1173  assert(exception->signature == MagickCoreSignature);
1174  (void) passphrase;
1175  ThrowBinaryException(ImageError,"CipherSupportNotEnabled",image->filename);
1176 }
1177 
1179  const StringInfo *passkey,ExceptionInfo *exception)
1180 {
1181  assert(image != (Image *) NULL);
1182  assert(image->signature == MagickCoreSignature);
1183  if (image->debug != MagickFalse)
1184  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1185  assert(exception != (ExceptionInfo *) NULL);
1186  assert(exception->signature == MagickCoreSignature);
1187  (void) passkey;
1188  ThrowBinaryException(ImageError,"CipherSupportNotEnabled",image->filename);
1189 }
1190 #endif
size_t rows
Definition: image.h:172
#define magick_restrict
Definition: MagickCore.h:41
MagickExport CacheView * DestroyCacheView(CacheView *cache_view)
Definition: cache-view.c:252
MagickExport StringInfo * StringToStringInfo(const char *string)
Definition: string.c:2478
#define ThrowFatalException(severity, tag)
#define RotateRight(x, n)
size_t signature
Definition: exception.h:123
MagickPrivate SignatureInfo * AcquireSignatureInfo(void)
MagickBooleanType taint
Definition: image.h:169
MagickExport MagickBooleanType DecipherImage(Image *image, const char *passphrase, ExceptionInfo *exception)
Definition: cipher.c:1109
#define ThrowBinaryException(severity, tag, context)
Definition: log.h:52
ssize_t MagickOffsetType
Definition: magick-type.h:133
Definition: image.h:151
#define MagickCoreSignature
MagickPrivate void FinalizeSignature(SignatureInfo *)
MagickExport Quantum * GetCacheViewAuthenticPixels(CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: cache-view.c:299
MagickPrivate SignatureInfo * DestroySignatureInfo(SignatureInfo *)
Definition: signature.c:171
MagickExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
Definition: string.c:1176
MagickBooleanType
Definition: magick-type.h:165
MagickExport size_t ImportQuantumPixels(const Image *image, CacheView *image_view, QuantumInfo *quantum_info, const QuantumType quantum_type, const unsigned char *magick_restrict pixels, ExceptionInfo *exception)
MagickExport MagickBooleanType PasskeyEncipherImage(Image *image, const StringInfo *passkey, ExceptionInfo *exception)
Definition: cipher.c:1178
MagickExport void * AcquireCriticalMemory(const size_t size)
Definition: memory.c:626
MagickExport StringInfo * DestroyStringInfo(StringInfo *string_info)
Definition: string.c:815
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:665
MagickExport MagickBooleanType SetImageProperty(Image *image, const char *property, const char *value, ExceptionInfo *exception)
Definition: property.c:4235
MagickExport MagickBooleanType PasskeyDecipherImage(Image *image, const StringInfo *passkey, ExceptionInfo *exception)
Definition: cipher.c:1122
size_t MagickSizeType
Definition: magick-type.h:134
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1660
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
MagickExport void * ResetMagickMemory(void *memory, int c, const size_t size)
Definition: memory.c:1290
MagickExport size_t ExportQuantumPixels(const Image *image, CacheView *image_view, QuantumInfo *quantum_info, const QuantumType quantum_type, unsigned char *magick_restrict pixels, ExceptionInfo *exception)
MagickExport unsigned char * GetQuantumPixels(const QuantumInfo *quantum_info)
Definition: quantum.c:489
MagickExport MagickBooleanType SetImageStorageClass(Image *image, const ClassType storage_class, ExceptionInfo *exception)
Definition: image.c:2614
MagickExport StringInfo * AcquireStringInfo(const size_t length)
Definition: string.c:151
MagickPrivate void UpdateSignature(SignatureInfo *, const StringInfo *)
Definition: signature.c:766
char filename[MagickPathExtent]
Definition: image.h:319
#define GetMagickModule()
Definition: log.h:28
MagickExport MagickBooleanType EncipherImage(Image *image, const char *passphrase, ExceptionInfo *exception)
Definition: cipher.c:1165
unsigned short Quantum
Definition: magick-type.h:86
MagickExport void SetStringInfoLength(StringInfo *string_info, const size_t length)
Definition: string.c:1706
MagickExport char * DestroyString(char *string)
Definition: string.c:788
MagickExport MagickBooleanType DeleteImageProperty(Image *image, const char *property)
Definition: property.c:279
#define MagickMin(x, y)
Definition: image-private.h:37
QuantumType
Definition: quantum.h:51
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1162
MagickPrivate const StringInfo * GetSignatureDigest(const SignatureInfo *)
Definition: signature.c:327
#define MagickExport
MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(CacheView *magick_restrict cache_view, ExceptionInfo *exception)
Definition: cache-view.c:1100
MagickExport StringInfo * SplitStringInfo(StringInfo *string_info, const size_t offset)
Definition: string.c:1812
MagickExport CacheView * AcquireAuthenticCacheView(const Image *image, ExceptionInfo *exception)
Definition: cache-view.c:112
MagickExport char * StringInfoToHexString(const StringInfo *string_info)
Definition: string.c:1890
MagickPrivate unsigned int GetSignatureDigestsize(const SignatureInfo *)
Definition: signature.c:358
MagickExport size_t GetStringInfoLength(const StringInfo *string_info)
Definition: string.c:1205
MagickExport QuantumInfo * AcquireQuantumInfo(const ImageInfo *image_info, Image *image)
Definition: quantum.c:110
MagickExport StringInfo * CloneStringInfo(const StringInfo *string_info)
Definition: string.c:302
MagickExport MagickBooleanType SetImageProgress(const Image *image, const char *tag, const MagickOffsetType offset, const MagickSizeType extent)
Definition: monitor.c:136
MagickExport void SetStringInfoDatum(StringInfo *string_info, const unsigned char *source)
Definition: string.c:1673
MagickExport QuantumInfo * DestroyQuantumInfo(QuantumInfo *quantum_info)
Definition: quantum.c:213
MagickBooleanType debug
Definition: image.h:334
MagickExport QuantumType GetQuantumType(Image *image, ExceptionInfo *exception)
Definition: quantum.c:523