Coverage Report

Created: 2025-06-22 07:35

/src/libewf/libewf/libewf_hash_values.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Hash values functions
3
 *
4
 * Copyright (C) 2006-2024, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <memory.h>
24
#include <narrow_string.h>
25
#include <types.h>
26
27
#include "libewf_definitions.h"
28
#include "libewf_hash_values.h"
29
#include "libewf_libcerror.h"
30
#include "libewf_libcnotify.h"
31
#include "libewf_libfvalue.h"
32
#include "libewf_libuna.h"
33
#include "libewf_value_table.h"
34
35
/* Creates hash values
36
 * Make sure the value hash_values is referencing, is set to NULL
37
 * Returns 1 if successful or -1 on error
38
 */
39
int libewf_hash_values_initialize(
40
     libfvalue_table_t **hash_values,
41
     libcerror_error_t **error )
42
0
{
43
0
  static char *function = "libewf_hash_values_initialize";
44
45
0
  if( libfvalue_table_initialize(
46
0
       hash_values,
47
0
       LIBEWF_HASH_VALUES_DEFAULT_NUMBER,
48
0
       error ) != 1 )
49
0
  {
50
0
    libcerror_error_set(
51
0
     error,
52
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
53
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
54
0
     "%s: unable to create hash values.",
55
0
     function );
56
57
0
    return( -1 );
58
0
  }
59
0
  return( 1 );
60
0
}
61
62
/* Parses a MD5 hash for its value
63
 * Returns 1 if successful or -1 on error
64
 */
65
int libewf_hash_values_parse_md5_hash(
66
     libfvalue_table_t *hash_values,
67
     const uint8_t *md5_hash,
68
     size_t md5_hash_size,
69
     libcerror_error_t **error )
70
0
{
71
0
  uint8_t md5_hash_string[ 33 ];
72
73
0
  libfvalue_value_t *hash_value = NULL;
74
0
  static char *function         = "libewf_hash_values_parse_md5_hash";
75
0
  size_t md5_hash_index         = 0;
76
0
  size_t md5_hash_string_index  = 0;
77
0
  uint8_t md5_digit             = 0;
78
0
  int result                    = 0;
79
80
0
  if( md5_hash == NULL )
81
0
  {
82
0
    libcerror_error_set(
83
0
     error,
84
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
85
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
86
0
     "%s: invalid MD5 hash.",
87
0
     function );
88
89
0
    return( -1 );
90
0
  }
91
0
  if( ( md5_hash_size < 16 )
92
0
   || ( md5_hash_size > (size_t) SSIZE_MAX ) )
93
0
  {
94
0
    libcerror_error_set(
95
0
     error,
96
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
97
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
98
0
     "%s: invalid MD5 hash size value out of bounds.",
99
0
     function );
100
101
0
    return( -1 );
102
0
  }
103
/* TODO replace by libfvalue_table_has_value_with_identifier */
104
0
  result = libfvalue_table_get_value_by_identifier(
105
0
            hash_values,
106
0
            (uint8_t *) "MD5",
107
0
            4,
108
0
            &hash_value,
109
0
            0,
110
0
            error );
111
112
0
  if( result == -1 )
113
0
  {
114
0
    libcerror_error_set(
115
0
     error,
116
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
117
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
118
0
     "%s: unable to retrieve if hash value: MD5.",
119
0
     function );
120
121
0
    return( -1 );
122
0
  }
123
0
  else if( result == 0 )
124
0
  {
125
0
    for( md5_hash_index = 0;
126
0
         md5_hash_index < md5_hash_size;
127
0
         md5_hash_index++ )
128
0
    {
129
0
      md5_digit = md5_hash[ md5_hash_index ] / 16;
130
131
0
      if( md5_digit <= 9 )
132
0
      {
133
0
        md5_hash_string[ md5_hash_string_index++ ] = (uint8_t) '0' + md5_digit;
134
0
      }
135
0
      else
136
0
      {
137
0
        md5_hash_string[ md5_hash_string_index++ ] = (uint8_t) 'a' + ( md5_digit - 10 );
138
0
      }
139
0
      md5_digit = md5_hash[ md5_hash_index ] % 16;
140
141
0
      if( md5_digit <= 9 )
142
0
      {
143
0
        md5_hash_string[ md5_hash_string_index++ ] = (uint8_t) '0' + md5_digit;
144
0
      }
145
0
      else
146
0
      {
147
0
        md5_hash_string[ md5_hash_string_index++ ] = (uint8_t) 'a' + ( md5_digit - 10 );
148
0
      }
149
0
    }
150
0
    md5_hash_string[ md5_hash_string_index++ ] = 0;
151
152
0
    if( libewf_value_table_set_value_by_identifier(
153
0
         hash_values,
154
0
         (uint8_t *) "MD5",
155
0
         4,
156
0
         (uint8_t *) md5_hash_string,
157
0
         33,
158
0
         error ) != 1 )
159
0
    {
160
0
      libcerror_error_set(
161
0
       error,
162
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
163
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
164
0
       "%s: unable to set hash value: MD5.",
165
0
       function );
166
167
0
      return( -1 );
168
0
    }
169
0
  }
170
0
  return( 1 );
171
0
}
172
173
/* Parses a SHA1 hash for its value
174
 * Returns 1 if successful or -1 on error
175
 */
176
int libewf_hash_values_parse_sha1_hash(
177
     libfvalue_table_t *hash_values,
178
     const uint8_t *sha1_hash,
179
     size_t sha1_hash_size,
180
     libcerror_error_t **error )
181
0
{
182
0
  uint8_t sha1_hash_string[ 41 ];
183
184
0
  libfvalue_value_t *hash_value = NULL;
185
0
  static char *function         = "libewf_hash_values_parse_sha1_hash";
186
0
  size_t sha1_hash_index        = 0;
187
0
  size_t sha1_hash_string_index = 0;
188
0
  int result                    = 0;
189
0
  uint8_t sha1_digit            = 0;
190
191
0
  if( hash_values == NULL )
192
0
  {
193
0
    libcerror_error_set(
194
0
     error,
195
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
196
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
197
0
     "%s: invalid hash values.",
198
0
     function );
199
200
0
    return( -1 );
201
0
  }
202
0
  if( sha1_hash == NULL )
203
0
  {
204
0
    libcerror_error_set(
205
0
     error,
206
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
207
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
208
0
     "%s: invalid SHA1 hash.",
209
0
     function );
210
211
0
    return( -1 );
212
0
  }
213
0
  if( ( sha1_hash_size < 20 )
214
0
   || ( sha1_hash_size > (size_t) SSIZE_MAX ) )
215
0
  {
216
0
    libcerror_error_set(
217
0
     error,
218
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
219
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
220
0
     "%s: invalid SHA1 hash size value out of bounds.",
221
0
     function );
222
223
0
    return( -1 );
224
0
  }
225
/* TODO replace by libfvalue_table_has_value_with_identifier */
226
0
  result = libfvalue_table_get_value_by_identifier(
227
0
            hash_values,
228
0
            (uint8_t *) "SHA1",
229
0
            5,
230
0
            &hash_value,
231
0
            0,
232
0
            error );
233
234
0
  if( result == -1 )
235
0
  {
236
0
    libcerror_error_set(
237
0
     error,
238
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
239
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
240
0
     "%s: unable to retrieve if hash value: SHA1.",
241
0
     function );
242
243
0
    return( -1 );
244
0
  }
245
0
  else if( result == 0 )
246
0
  {
247
0
    for( sha1_hash_index = 0;
248
0
         sha1_hash_index < sha1_hash_size;
249
0
         sha1_hash_index++ )
250
0
    {
251
0
      sha1_digit = sha1_hash[ sha1_hash_index ] / 16;
252
253
0
      if( sha1_digit <= 9 )
254
0
      {
255
0
        sha1_hash_string[ sha1_hash_string_index++ ] = (uint8_t) '0' + sha1_digit;
256
0
      }
257
0
      else
258
0
      {
259
0
        sha1_hash_string[ sha1_hash_string_index++ ] = (uint8_t) 'a' + ( sha1_digit - 10 );
260
0
      }
261
0
      sha1_digit = sha1_hash[ sha1_hash_index ] % 16;
262
263
0
      if( sha1_digit <= 9 )
264
0
      {
265
0
        sha1_hash_string[ sha1_hash_string_index++ ] = (uint8_t) '0' + sha1_digit;
266
0
      }
267
0
      else
268
0
      {
269
0
        sha1_hash_string[ sha1_hash_string_index++ ] = (uint8_t) 'a' + ( sha1_digit - 10 );
270
0
      }
271
0
    }
272
0
    sha1_hash_string[ sha1_hash_string_index++ ] = 0;
273
274
0
    if( libewf_value_table_set_value_by_identifier(
275
0
         hash_values,
276
0
         (uint8_t *) "SHA1",
277
0
         5,
278
0
         (uint8_t *) sha1_hash_string,
279
0
         41,
280
0
         error ) != 1 )
281
0
    {
282
0
      libcerror_error_set(
283
0
       error,
284
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
285
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
286
0
       "%s: unable to set hash value: SHA1.",
287
0
       function );
288
289
0
      return( -1 );
290
0
    }
291
0
  }
292
0
  return( 1 );
293
0
}
294
295
/* Parses a xhash for the hash values
296
 * Returns 1 if successful or -1 on error
297
 */
298
int libewf_hash_values_parse_xhash(
299
     libfvalue_table_t *hash_values,
300
     const uint8_t *xhash,
301
     size_t xhash_size,
302
     libcerror_error_t **error )
303
0
{
304
0
  static char *function = "libewf_hash_values_parse_xhash";
305
306
0
  if( libfvalue_table_copy_from_utf8_xml_string(
307
0
       hash_values,
308
0
       xhash,
309
0
       xhash_size,
310
0
       (uint8_t *) "xhash",
311
0
       5,
312
0
       error ) != 1 )
313
0
  {
314
0
    libcerror_error_set(
315
0
     error,
316
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
317
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
318
0
     "%s: unable to copy UTF-8 string to hash values table.",
319
0
     function );
320
321
0
    return( -1 );
322
0
  }
323
0
  return( 1 );
324
0
}
325
326
/* Generate a xhash
327
 * Sets xhash and xhash size
328
 * Returns 1 if successful or -1 on error
329
 */
330
int libewf_hash_values_generate_xhash(
331
     libfvalue_table_t *hash_values,
332
     uint8_t **xhash,
333
     size_t *xhash_size,
334
     libcerror_error_t **error )
335
0
{
336
0
  libfvalue_value_t *hash_value     = NULL;
337
0
  uint8_t *identifier               = NULL;
338
0
  char *xml_head                    = NULL;
339
0
  char *xml_xhash_close_tag         = NULL;
340
0
  char *xml_xhash_open_tag          = NULL;
341
0
  static char *function             = "libewf_hash_values_generate_xhash";
342
0
  size_t xhash_index                = 0;
343
0
  size_t identifier_size            = 0;
344
0
  size_t value_string_size          = 0;
345
0
  size_t xml_head_length            = 0;
346
0
  size_t xml_xhash_close_tag_length = 0;
347
0
  size_t xml_xhash_open_tag_length  = 0;
348
0
  int hash_value_index              = 0;
349
0
  int number_of_hash_values         = 0;
350
0
  int result                        = 0;
351
352
0
  if( xhash == NULL )
353
0
  {
354
0
    libcerror_error_set(
355
0
     error,
356
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
357
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
358
0
     "%s: invalid xhash.",
359
0
     function );
360
361
0
    return( -1 );
362
0
  }
363
0
  if( *xhash != NULL )
364
0
  {
365
0
    libcerror_error_set(
366
0
     error,
367
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
368
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
369
0
     "%s: xhash already created.",
370
0
     function );
371
372
0
    return( -1 );
373
0
  }
374
0
  if( xhash_size == NULL )
375
0
  {
376
0
    libcerror_error_set(
377
0
     error,
378
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
379
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
380
0
     "%s: invalid xhash size.",
381
0
     function );
382
383
0
    return( -1 );
384
0
  }
385
0
  if( libfvalue_table_get_number_of_values(
386
0
       hash_values,
387
0
       &number_of_hash_values,
388
0
       error ) != 1 )
389
0
  {
390
0
    libcerror_error_set(
391
0
     error,
392
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
393
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
394
0
     "%s: unable to retrieve number of hash values.",
395
0
     function );
396
397
0
    goto on_error;
398
0
  }
399
0
  xml_head = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
400
401
0
  xml_head_length = narrow_string_length(
402
0
                     xml_head );
403
404
0
  xml_xhash_open_tag = "<xhash>\n";
405
406
0
  xml_xhash_open_tag_length = narrow_string_length(
407
0
                               xml_xhash_open_tag );
408
409
0
  xml_xhash_close_tag = "</xhash>\n\n";
410
411
0
  xml_xhash_close_tag_length = narrow_string_length(
412
0
                                xml_xhash_close_tag );
413
414
  /* Reserve space for the UTF-8 byte order mark and the XML skeleton data
415
   */
416
0
  *xhash_size = 3 + xml_head_length + xml_xhash_open_tag_length + xml_xhash_close_tag_length;
417
418
0
  for( hash_value_index = 0;
419
0
       hash_value_index < number_of_hash_values;
420
0
       hash_value_index++ )
421
0
  {
422
0
    if( libfvalue_table_get_value_by_index(
423
0
         hash_values,
424
0
         hash_value_index,
425
0
         &hash_value,
426
0
         error ) != 1 )
427
0
    {
428
0
      libcerror_error_set(
429
0
       error,
430
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
431
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
432
0
       "%s: unable to retrieve hash value: %d.",
433
0
       function,
434
0
       hash_value_index );
435
436
0
      goto on_error;
437
0
    }
438
0
    if( libfvalue_value_get_identifier(
439
0
         hash_value,
440
0
         &identifier,
441
0
         &identifier_size,
442
0
         error ) != 1 )
443
0
    {
444
0
      libcerror_error_set(
445
0
       error,
446
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
447
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
448
0
       "%s: unable to retrieve identifier of hash value: %d.",
449
0
       function,
450
0
       hash_value_index );
451
452
0
      goto on_error;
453
0
    }
454
0
    if( ( identifier == NULL )
455
0
     || ( identifier_size == 0 ) )
456
0
    {
457
#if defined( HAVE_VERBOSE_OUTPUT )
458
      if( libcnotify_verbose != 0 )
459
      {
460
        libcnotify_printf(
461
         "%s: missing identifier for hash value: %d.\n",
462
         function,
463
         hash_value_index );
464
      }
465
#endif
466
0
      continue;
467
0
    }
468
0
    result = libfvalue_value_get_utf8_string_size(
469
0
              hash_value,
470
0
              0,
471
0
              &value_string_size,
472
0
              error );
473
474
0
    if( result != 1 )
475
0
    {
476
0
      libcerror_error_set(
477
0
       error,
478
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
479
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
480
0
       "%s: unable to retrieve string size of hash value: %s.",
481
0
       function,
482
0
       (char *) identifier );
483
484
0
      goto on_error;
485
0
    }
486
0
    if( ( result != 0 )
487
0
     && ( value_string_size > 1 ) )
488
0
    {
489
      /* Reserve space for a leading tab, <identifier>value</identifier> and a newline
490
       */
491
0
      *xhash_size += 7 + ( 2 * ( identifier_size - 1 ) ) + ( value_string_size - 1 );
492
0
    }
493
0
  }
494
  /* Reserve space for the end-of-string character
495
   */
496
0
  *xhash_size += 1;
497
498
0
  if( *xhash_size > MEMORY_MAXIMUM_ALLOCATION_SIZE )
499
0
  {
500
0
    libcerror_error_set(
501
0
     error,
502
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
503
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
504
0
     "%s: invalid xhash size value out of bounds.",
505
0
     function );
506
507
0
    goto on_error;
508
0
  }
509
0
  *xhash = (uint8_t *) memory_allocate(
510
0
                              sizeof( uint8_t ) * *xhash_size );
511
512
0
  if( *xhash == NULL )
513
0
  {
514
0
    libcerror_error_set(
515
0
     error,
516
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
517
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
518
0
     "%s: unable to create xhash.",
519
0
     function );
520
521
0
    goto on_error;
522
0
  }
523
0
  ( *xhash )[ xhash_index++ ] = 0xef;
524
0
  ( *xhash )[ xhash_index++ ] = 0xbb;
525
0
  ( *xhash )[ xhash_index++ ] = 0xbf;
526
527
0
  if( narrow_string_copy(
528
0
       (char *) &( ( *xhash )[ xhash_index ] ),
529
0
       xml_head,
530
0
       xml_head_length ) == NULL )
531
0
  {
532
0
    libcerror_error_set(
533
0
     error,
534
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
535
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
536
0
     "%s: unable to copy XML head string.",
537
0
     function );
538
539
0
    goto on_error;
540
0
  }
541
0
  xhash_index += xml_head_length;
542
543
0
  if( narrow_string_copy(
544
0
       (char *) &( ( *xhash )[ xhash_index ] ),
545
0
       xml_xhash_open_tag,
546
0
       xml_xhash_open_tag_length ) == NULL )
547
0
  {
548
0
    libcerror_error_set(
549
0
     error,
550
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
551
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
552
0
     "%s: unable to copy xhash open tag string.",
553
0
     function );
554
555
0
    goto on_error;
556
0
  }
557
0
  xhash_index += xml_xhash_open_tag_length;
558
559
0
  for( hash_value_index = 0;
560
0
       hash_value_index < number_of_hash_values;
561
0
       hash_value_index++ )
562
0
  {
563
0
    if( libfvalue_table_get_value_by_index(
564
0
         hash_values,
565
0
         hash_value_index,
566
0
         &hash_value,
567
0
         error ) != 1 )
568
0
    {
569
0
      libcerror_error_set(
570
0
       error,
571
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
572
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
573
0
       "%s: unable to retrieve hash value: %d.",
574
0
       function,
575
0
       hash_value_index );
576
577
0
      goto on_error;
578
0
    }
579
0
    if( libfvalue_value_get_identifier(
580
0
         hash_value,
581
0
         &identifier,
582
0
         &identifier_size,
583
0
         error ) != 1 )
584
0
    {
585
0
      libcerror_error_set(
586
0
       error,
587
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
588
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
589
0
       "%s: unable to retrieve identifier of hash value: %d.",
590
0
       function,
591
0
       hash_value_index );
592
593
0
      goto on_error;
594
0
    }
595
0
    if( ( identifier == NULL )
596
0
     || ( identifier_size == 0 ) )
597
0
    {
598
#if defined( HAVE_VERBOSE_OUTPUT )
599
      if( libcnotify_verbose != 0 )
600
      {
601
        libcnotify_printf(
602
         "%s: missing identifier for hash value: %d.\n",
603
         function,
604
         hash_value_index );
605
      }
606
#endif
607
0
      continue;
608
0
    }
609
0
    result = libfvalue_value_get_utf8_string_size(
610
0
              hash_value,
611
0
              0,
612
0
              &value_string_size,
613
0
              error );
614
615
0
    if( result == -1 )
616
0
    {
617
0
      libcerror_error_set(
618
0
       error,
619
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
620
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
621
0
       "%s: unable to retrieve string size of hash value: %s.",
622
0
       function,
623
0
       (char *) identifier );
624
625
0
      goto on_error;
626
0
    }
627
0
    if( ( result != 0 )
628
0
     && ( value_string_size > 1 ) )
629
0
    {
630
0
      ( *xhash )[ xhash_index++ ] = (uint8_t) '\t';
631
0
      ( *xhash )[ xhash_index++ ] = (uint8_t) '<';
632
633
0
      if( narrow_string_copy(
634
0
           (char *) &( ( *xhash )[ xhash_index ] ),
635
0
           (char *) identifier,
636
0
           identifier_size - 1 ) == NULL )
637
0
      {
638
0
        libcerror_error_set(
639
0
         error,
640
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
641
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
642
0
         "%s: unable to copy %s open tag string.",
643
0
         function,
644
0
         (char *) identifier );
645
646
0
        goto on_error;
647
0
      }
648
0
      xhash_index += identifier_size - 1;
649
650
0
      ( *xhash )[ xhash_index++ ] = (uint8_t) '>';
651
652
0
      if( libfvalue_value_copy_to_utf8_string_with_index(
653
0
           hash_value,
654
0
           0,
655
0
           *xhash,
656
0
           *xhash_size,
657
0
           &xhash_index,
658
0
           error ) != 1 )
659
0
      {
660
0
        libcerror_error_set(
661
0
         error,
662
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
663
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
664
0
         "%s: unable to copy string of hash value: %s.",
665
0
         function,
666
0
         (char *) identifier );
667
668
0
        goto on_error;
669
0
      }
670
0
      ( *xhash )[ xhash_index - 1 ] = (uint8_t) '<';
671
0
      ( *xhash )[ xhash_index++   ] = (uint8_t) '/';
672
673
0
      if( narrow_string_copy(
674
0
           (char *) &( ( *xhash )[ xhash_index ] ),
675
0
           (char *) identifier,
676
0
           identifier_size - 1 ) == NULL )
677
0
      {
678
0
        libcerror_error_set(
679
0
         error,
680
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
681
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
682
0
         "%s: unable to copy %s close tag string.",
683
0
         function,
684
0
         (char *) identifier );
685
686
0
        goto on_error;
687
0
      }
688
0
      xhash_index += identifier_size - 1;
689
690
0
      ( *xhash )[ xhash_index++ ] = (uint8_t) '>';
691
0
      ( *xhash )[ xhash_index++ ] = (uint8_t) '\n';
692
0
    }
693
0
  }
694
0
  if( narrow_string_copy(
695
0
       (char *) &( ( *xhash )[ xhash_index ] ),
696
0
       xml_xhash_close_tag,
697
0
       xml_xhash_close_tag_length ) == NULL )
698
0
  {
699
0
    libcerror_error_set(
700
0
     error,
701
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
702
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
703
0
     "%s: unable to copy xhash close tag string.",
704
0
     function );
705
706
0
    goto on_error;
707
0
  }
708
0
  xhash_index += xml_xhash_close_tag_length;
709
710
  /* Make sure the string is terminated
711
   */
712
0
  ( *xhash )[ xhash_index ] = 0;
713
714
0
  return( 1 );
715
716
0
on_error:
717
0
  if( *xhash != NULL )
718
0
  {
719
0
    memory_free(
720
0
     *xhash );
721
722
0
    *xhash = NULL;
723
0
  }
724
0
  *xhash_size = 0;
725
726
0
  return( -1 );
727
0
}
728
729
/* Generate a MD5 hash
730
 * Returns 1 if successful or -1 on error
731
 */
732
int libewf_hash_values_generate_md5_hash(
733
     libfvalue_table_t *hash_values,
734
     uint8_t *md5_hash,
735
     size_t md5_hash_size,
736
     uint8_t *md5_hash_set,
737
     libcerror_error_t **error )
738
0
{
739
0
  uint8_t md5_hash_string[ 33 ];
740
741
0
  libfvalue_value_t *hash_value = NULL;
742
0
  static char *function         = "libewf_hash_values_generate_md5_hash";
743
0
  size_t md5_hash_index         = 0;
744
0
  size_t md5_hash_string_index  = 0;
745
0
  uint8_t md5_digit             = 0;
746
0
  int result                    = 0;
747
748
0
  if( hash_values == NULL )
749
0
  {
750
0
    libcerror_error_set(
751
0
     error,
752
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
753
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
754
0
     "%s: invalid hash values.",
755
0
     function );
756
757
0
    return( -1 );
758
0
  }
759
0
  if( md5_hash == NULL )
760
0
  {
761
0
    libcerror_error_set(
762
0
     error,
763
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
764
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
765
0
     "%s: invalid MD5 hash.",
766
0
     function );
767
768
0
    return( -1 );
769
0
  }
770
0
  if( md5_hash_size < 16 )
771
0
  {
772
0
    libcerror_error_set(
773
0
     error,
774
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
775
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
776
0
     "%s: MD5 hash too small.",
777
0
     function );
778
779
0
    return( -1 );
780
0
  }
781
0
  if( md5_hash_set == NULL )
782
0
  {
783
0
    libcerror_error_set(
784
0
     error,
785
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
786
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
787
0
     "%s: invalid MD5 hash set.",
788
0
     function );
789
790
0
    return( -1 );
791
0
  }
792
0
  result = libfvalue_table_get_value_by_identifier(
793
0
            hash_values,
794
0
            (uint8_t *) "MD5",
795
0
            4,
796
0
            &hash_value,
797
0
            0,
798
0
            error );
799
800
0
  if( result == -1 )
801
0
  {
802
0
    libcerror_error_set(
803
0
     error,
804
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
805
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
806
0
     "%s: unable to retrieve if hash value: MD5.",
807
0
     function );
808
809
0
    return( -1 );
810
0
  }
811
  /* No need to generate the MD5 hash
812
   */
813
0
  else if( result == 0 )
814
0
  {
815
0
    *md5_hash_set = 0;
816
817
0
    return( 1 );
818
0
  }
819
0
  if( libfvalue_value_copy_to_utf8_string(
820
0
       hash_value,
821
0
       0,
822
0
       md5_hash_string,
823
0
       33,
824
0
       error ) != 1 )
825
0
  {
826
0
    libcerror_error_set(
827
0
     error,
828
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
829
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
830
0
     "%s: unable to copy hash value: MD5 to UTF-8 string.",
831
0
     function );
832
833
0
    return( -1 );
834
0
  }
835
0
  while( md5_hash_string_index < 32 )
836
0
  {
837
0
    if( ( md5_hash_string[ md5_hash_string_index ] >= (uint8_t) '0' )
838
0
     && ( md5_hash_string[ md5_hash_string_index ] <= (uint8_t) '9' ) )
839
0
    {
840
0
      md5_digit = (uint8_t) ( md5_hash_string[ md5_hash_string_index ] - (uint8_t) '0' );
841
0
    }
842
0
    else if( ( md5_hash_string[ md5_hash_string_index ] >= (uint8_t) 'A' )
843
0
          && ( md5_hash_string[ md5_hash_string_index ] <= (uint8_t) 'F' ) )
844
0
    {
845
0
      md5_digit = 10 + (uint8_t) ( md5_hash_string[ md5_hash_string_index ] - (uint8_t) 'A' );
846
0
    }
847
0
    else if( ( md5_hash_string[ md5_hash_string_index ] >= (uint8_t) 'a' )
848
0
          && ( md5_hash_string[ md5_hash_string_index ] <= (uint8_t) 'f' ) )
849
0
    {
850
0
      md5_digit = 10 + (uint8_t) ( md5_hash_string[ md5_hash_string_index ] - (uint8_t) 'a' );
851
0
    }
852
0
    else if( md5_hash_string[ md5_hash_string_index ] == 0 )
853
0
    {
854
0
      md5_digit = 0;
855
0
    }
856
0
    else
857
0
    {
858
0
      libcerror_error_set(
859
0
       error,
860
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
861
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
862
0
       "%s: invalid hexadecimal digit: 0x%02" PRIx8 " in MD5 string.",
863
0
       function,
864
0
       md5_hash_string[ md5_hash_string_index ] );
865
866
0
      return( -1 );
867
0
    }
868
0
    md5_hash_string_index++;
869
870
0
    md5_digit <<= 4;
871
872
0
    if( ( md5_hash_string[ md5_hash_string_index ] >= (uint8_t) '0' )
873
0
     && ( md5_hash_string[ md5_hash_string_index ] <= (uint8_t) '9' ) )
874
0
    {
875
0
      md5_digit += (uint8_t) ( md5_hash_string[ md5_hash_string_index ] - (uint8_t) '0' );
876
0
    }
877
0
    else if( ( md5_hash_string[ md5_hash_string_index ] >= (uint8_t) 'A' )
878
0
          && ( md5_hash_string[ md5_hash_string_index ] <= (uint8_t) 'F' ) )
879
0
    {
880
0
      md5_digit += 10 + (uint8_t) ( md5_hash_string[ md5_hash_string_index ] - (uint8_t) 'A' );
881
0
    }
882
0
    else if( ( md5_hash_string[ md5_hash_string_index ] >= (uint8_t) 'a' )
883
0
          && ( md5_hash_string[ md5_hash_string_index ] <= (uint8_t) 'f' ) )
884
0
    {
885
0
      md5_digit += 10 + (uint8_t) ( md5_hash_string[ md5_hash_string_index ] - (uint8_t) 'a' );
886
0
    }
887
0
    else if( md5_hash_string[ md5_hash_string_index ] != 0 )
888
0
    {
889
0
      libcerror_error_set(
890
0
       error,
891
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
892
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
893
0
       "%s: invalid hexadecimal digit: 0x%02" PRIx8 " in MD5 string.",
894
0
       function,
895
0
       md5_hash_string[ md5_hash_string_index ] );
896
897
0
      return( -1 );
898
0
    }
899
0
    md5_hash_string_index++;
900
901
0
    md5_hash[ md5_hash_index++ ] = md5_digit;
902
0
  }
903
0
  *md5_hash_set = 1;
904
905
0
  return( 1 );
906
0
}
907
908
/* Generate a SHA1 hash
909
 * Returns 1 if successful or -1 on error
910
 */
911
int libewf_hash_values_generate_sha1_hash(
912
     libfvalue_table_t *hash_values,
913
     uint8_t *sha1_hash,
914
     size_t sha1_hash_size,
915
     uint8_t *sha1_hash_set,
916
     libcerror_error_t **error )
917
0
{
918
0
  uint8_t sha1_hash_string[ 41 ];
919
920
0
  libfvalue_value_t *hash_value = NULL;
921
0
  static char *function         = "libewf_hash_values_generate_sha1_hash";
922
0
  size_t sha1_hash_index        = 0;
923
0
  size_t sha1_hash_string_index = 0;
924
0
  uint8_t sha1_digit            = 0;
925
0
  int result                    = 0;
926
927
0
  if( hash_values == NULL )
928
0
  {
929
0
    libcerror_error_set(
930
0
     error,
931
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
932
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
933
0
     "%s: invalid hash values.",
934
0
     function );
935
936
0
    return( -1 );
937
0
  }
938
0
  if( sha1_hash == NULL )
939
0
  {
940
0
    libcerror_error_set(
941
0
     error,
942
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
943
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
944
0
     "%s: invalid SHA1 hash.",
945
0
     function );
946
947
0
    return( -1 );
948
0
  }
949
0
  if( sha1_hash_size < 20 )
950
0
  {
951
0
    libcerror_error_set(
952
0
     error,
953
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
954
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
955
0
     "%s: SHA1 hash too small.",
956
0
     function );
957
958
0
    return( -1 );
959
0
  }
960
0
  if( sha1_hash_set == NULL )
961
0
  {
962
0
    libcerror_error_set(
963
0
     error,
964
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
965
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
966
0
     "%s: invalid SHA1 hash set.",
967
0
     function );
968
969
0
    return( -1 );
970
0
  }
971
0
  result = libfvalue_table_get_value_by_identifier(
972
0
            hash_values,
973
0
            (uint8_t *) "SHA1",
974
0
            5,
975
0
            &hash_value,
976
0
            0,
977
0
            error );
978
979
0
  if( result == -1 )
980
0
  {
981
0
    libcerror_error_set(
982
0
     error,
983
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
984
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
985
0
     "%s: unable to retrieve if hash value: SHA1.",
986
0
     function );
987
988
0
    return( -1 );
989
0
  }
990
  /* No need to generate the SHA1 hash
991
   */
992
0
  else if( result == 0 )
993
0
  {
994
0
    *sha1_hash_set = 0;
995
996
0
    return( 1 );
997
0
  }
998
0
  if( libfvalue_value_copy_to_utf8_string(
999
0
       hash_value,
1000
0
       0,
1001
0
       sha1_hash_string,
1002
0
       41,
1003
0
       error ) != 1 )
1004
0
  {
1005
0
    libcerror_error_set(
1006
0
     error,
1007
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1008
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1009
0
     "%s: unable to copy hash value: SHA1 to UTF-8 string.",
1010
0
     function );
1011
1012
0
    return( -1 );
1013
0
  }
1014
0
  while( sha1_hash_string_index < 40 )
1015
0
  {
1016
0
    if( ( sha1_hash_string[ sha1_hash_string_index ] >= (uint8_t) '0' )
1017
0
     && ( sha1_hash_string[ sha1_hash_string_index ] <= (uint8_t) '9' ) )
1018
0
    {
1019
0
      sha1_digit = (uint8_t) ( sha1_hash_string[ sha1_hash_string_index ] - (uint8_t) '0' );
1020
0
    }
1021
0
    else if( ( sha1_hash_string[ sha1_hash_string_index ] >= (uint8_t) 'A' )
1022
0
          && ( sha1_hash_string[ sha1_hash_string_index ] <= (uint8_t) 'F' ) )
1023
0
    {
1024
0
      sha1_digit = 10 + (uint8_t) ( sha1_hash_string[ sha1_hash_string_index ] - (uint8_t) 'A' );
1025
0
    }
1026
0
    else if( ( sha1_hash_string[ sha1_hash_string_index ] >= (uint8_t) 'a' )
1027
0
          && ( sha1_hash_string[ sha1_hash_string_index ] <= (uint8_t) 'f' ) )
1028
0
    {
1029
0
      sha1_digit = 10 + (uint8_t) ( sha1_hash_string[ sha1_hash_string_index ] - (uint8_t) 'a' );
1030
0
    }
1031
0
    else if( sha1_hash_string[ sha1_hash_string_index ] == 0 )
1032
0
    {
1033
0
      sha1_digit = 0;
1034
0
    }
1035
0
    else
1036
0
    {
1037
0
      libcerror_error_set(
1038
0
       error,
1039
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1040
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1041
0
       "%s: invalid hexadecimal digit: 0x%02" PRIx8 " in SHA1 string.",
1042
0
       function,
1043
0
       sha1_hash_string[ sha1_hash_string_index ] );
1044
1045
0
      return( -1 );
1046
0
    }
1047
0
    sha1_hash_string_index++;
1048
1049
0
    sha1_digit <<= 4;
1050
1051
0
    if( ( sha1_hash_string[ sha1_hash_string_index ] >= (uint8_t) '0' )
1052
0
     && ( sha1_hash_string[ sha1_hash_string_index ] <= (uint8_t) '9' ) )
1053
0
    {
1054
0
      sha1_digit += (uint8_t) ( sha1_hash_string[ sha1_hash_string_index ] - (uint8_t) '0' );
1055
0
    }
1056
0
    else if( ( sha1_hash_string[ sha1_hash_string_index ] >= (uint8_t) 'A' )
1057
0
          && ( sha1_hash_string[ sha1_hash_string_index ] <= (uint8_t) 'F' ) )
1058
0
    {
1059
0
      sha1_digit += 10 + (uint8_t) ( sha1_hash_string[ sha1_hash_string_index ] - (uint8_t) 'A' );
1060
0
    }
1061
0
    else if( ( sha1_hash_string[ sha1_hash_string_index ] >= (uint8_t) 'a' )
1062
0
          && ( sha1_hash_string[ sha1_hash_string_index ] <= (uint8_t) 'f' ) )
1063
0
    {
1064
0
      sha1_digit += 10 + (uint8_t) ( sha1_hash_string[ sha1_hash_string_index ] - (uint8_t) 'a' );
1065
0
    }
1066
0
    else if( sha1_hash_string[ sha1_hash_string_index ] != 0 )
1067
0
    {
1068
0
      libcerror_error_set(
1069
0
       error,
1070
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1071
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1072
0
       "%s: invalid hexadecimal digit: 0x%02" PRIx8 " in SHA1 string.",
1073
0
       function,
1074
0
       sha1_hash_string[ sha1_hash_string_index ] );
1075
1076
0
      return( -1 );
1077
0
    }
1078
0
    sha1_hash_string_index++;
1079
1080
0
    sha1_hash[ sha1_hash_index++ ] = sha1_digit;
1081
0
  }
1082
0
  *sha1_hash_set = 1;
1083
1084
0
  return( 1 );
1085
0
}
1086
1087
/* Retrieves the size of the hash value identifier of a specific index
1088
 * The identifier size includes the end of string character
1089
 * Returns 1 if successful, 0 if if no hash values are present or -1 on error
1090
 */
1091
int libewf_hash_values_get_identifier_size(
1092
     libfvalue_table_t *hash_values,
1093
     uint32_t index,
1094
     size_t *identifier_size,
1095
     libcerror_error_t **error )
1096
0
{
1097
0
  libfvalue_value_t *hash_value  = NULL;
1098
0
  uint8_t *hash_value_identifier = NULL;
1099
0
  static char *function          = "libewf_hash_values_get_identifier_size";
1100
1101
0
  if( hash_values == NULL )
1102
0
  {
1103
0
    libcerror_error_set(
1104
0
     error,
1105
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1106
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1107
0
     "%s: invalid hash values.",
1108
0
     function );
1109
1110
0
    return( -1 );
1111
0
  }
1112
0
  if( libfvalue_table_get_value_by_index(
1113
0
       hash_values,
1114
0
       (int) index,
1115
0
       &hash_value,
1116
0
       error ) != 1 )
1117
0
  {
1118
0
    libcerror_error_set(
1119
0
     error,
1120
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1121
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1122
0
     "%s: unable to retrieve hash value: %" PRIu32 ".",
1123
0
     function,
1124
0
     index );
1125
1126
0
    return( -1 );
1127
0
  }
1128
0
  if( libfvalue_value_get_identifier(
1129
0
       hash_value,
1130
0
       &hash_value_identifier,
1131
0
       identifier_size,
1132
0
       error ) != 1 )
1133
0
  {
1134
0
    libcerror_error_set(
1135
0
     error,
1136
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1137
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1138
0
     "%s: unable to retrieve hash value: %" PRIu32 " identifier size.",
1139
0
     function,
1140
0
     index );
1141
1142
0
    return( -1 );
1143
0
  }
1144
0
  return( 1 );
1145
0
}
1146
1147
/* Retrieves the hash value identifier of a specific index
1148
 * The identifier size should include the end of string character
1149
 * Returns 1 if successful, 0 if no hash values are present or -1 on error
1150
 */
1151
int libewf_hash_values_get_identifier(
1152
     libfvalue_table_t *hash_values,
1153
     uint32_t index,
1154
     uint8_t *identifier,
1155
     size_t identifier_size,
1156
     libcerror_error_t **error )
1157
0
{
1158
0
  libfvalue_value_t *hash_value     = NULL;
1159
0
  uint8_t *hash_value_identifier    = NULL;
1160
0
  static char *function             = "libewf_hash_values_get_identifier";
1161
0
  size_t hash_value_identifier_size = 0;
1162
1163
0
  if( hash_values == NULL )
1164
0
  {
1165
0
    libcerror_error_set(
1166
0
     error,
1167
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1168
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1169
0
     "%s: invalid hash values.",
1170
0
     function );
1171
1172
0
    return( -1 );
1173
0
  }
1174
0
  if( identifier == NULL )
1175
0
  {
1176
0
    libcerror_error_set(
1177
0
     error,
1178
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1179
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1180
0
     "%s: invalid identifier.",
1181
0
     function );
1182
1183
0
    return( -1 );
1184
0
  }
1185
0
  if( identifier_size > (size_t) SSIZE_MAX )
1186
0
  {
1187
0
    libcerror_error_set(
1188
0
     error,
1189
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1190
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
1191
0
     "%s: invalid identifier size value exceeds maximum.",
1192
0
     function );
1193
1194
0
    return( -1 );
1195
0
  }
1196
0
  if( libfvalue_table_get_value_by_index(
1197
0
       hash_values,
1198
0
       (int) index,
1199
0
       &hash_value,
1200
0
       error ) != 1 )
1201
0
  {
1202
0
    libcerror_error_set(
1203
0
     error,
1204
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1205
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1206
0
     "%s: unable to retrieve hash value: %" PRIu32 ".",
1207
0
     function,
1208
0
     index );
1209
1210
0
    return( -1 );
1211
0
  }
1212
0
  if( libfvalue_value_get_identifier(
1213
0
       hash_value,
1214
0
       &hash_value_identifier,
1215
0
       &hash_value_identifier_size,
1216
0
       error ) != 1 )
1217
0
  {
1218
0
    libcerror_error_set(
1219
0
     error,
1220
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1221
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1222
0
     "%s: unable to retrieve hash value: %" PRIu32 " identifier size.",
1223
0
     function,
1224
0
     index );
1225
1226
0
    return( -1 );
1227
0
  }
1228
0
  if( identifier_size < hash_value_identifier_size )
1229
0
  {
1230
0
    libcerror_error_set(
1231
0
     error,
1232
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1233
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1234
0
     "%s: hash value: %" PRIu32 " identifier size too small.",
1235
0
     function,
1236
0
     index );
1237
1238
0
    return( -1 );
1239
0
  }
1240
0
  if( memory_copy(
1241
0
       identifier,
1242
0
       hash_value_identifier,
1243
0
       hash_value_identifier_size ) == NULL )
1244
0
  {
1245
0
    libcerror_error_set(
1246
0
     error,
1247
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1248
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1249
0
     "%s: unable to copy hash value: %" PRIu32 " identifier.",
1250
0
     function,
1251
0
     index );
1252
1253
0
    return( -1 );
1254
0
  }
1255
0
  return( 1 );
1256
0
}
1257