Debian Codegraph @

crt/aws-c-s3/tests/s3_checksums_crc64nvme_tests.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5 #include "aws/s3/private/s3_checksums.h"
6 #include <aws/common/byte_buf.h>
7 #include <aws/testing/aws_test_harness.h>
8
9 #include <s3_checksums_test_case_helper.h>
10 #define AWS_CRC64_LEN sizeof(uint64_t)
11
12 static int s_crc64nvme_nist_test_case_1_fn(struct aws_allocator *allocator, void *ctx) {
13 (void)ctx;
14
15 struct aws_byte_cursor input = aws_byte_cursor_from_c_str("aaaaaaaaaa");
16 uint8_t expected[] = {0x0C, 0x1A, 0x80, 0x03, 0x6D, 0x65, 0xC5, 0x55};
17 struct aws_byte_cursor expected_buf = aws_byte_cursor_from_array(expected, sizeof(expected));
18
19 return s_verify_checksum_test_case(allocator, &input, &expected_buf, aws_checksum_new, AWS_SCA_CRC64NVME);
20 }
21
22 AWS_TEST_CASE(crc64nvme_nist_test_case_1, s_crc64nvme_nist_test_case_1_fn)
23
24 static int s_crc64nvme_nist_test_case_2_fn(struct aws_allocator *allocator, void *ctx) {
25 (void)ctx;
26
27 struct aws_byte_cursor input = aws_byte_cursor_from_c_str("");
28 uint8_t expected[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
29 struct aws_byte_cursor expected_buf = aws_byte_cursor_from_array(expected, sizeof(expected));
30
31 return s_verify_checksum_test_case(allocator, &input, &expected_buf, aws_checksum_new, AWS_SCA_CRC64NVME);
32 }
33
34 AWS_TEST_CASE(crc64nvme_nist_test_case_2, s_crc64nvme_nist_test_case_2_fn)
35
36 static int s_crc64nvme_nist_test_case_3_fn(struct aws_allocator *allocator, void *ctx) {
37 (void)ctx;
38
39 aws_s3_library_init(allocator);
40
41 struct aws_s3_checksum *checksum = aws_checksum_new(allocator, AWS_SCA_CRC64NVME);
42 ASSERT_NOT_NULL(checksum);
43 struct aws_byte_cursor input = aws_byte_cursor_from_c_str("a");
44
45 for (size_t i = 0; i < 10; ++i) {
46 ASSERT_SUCCESS(aws_checksum_update(checksum, &input));
47 }
48
49 uint8_t output[AWS_CRC64_LEN] = {0};
50 struct aws_byte_buf output_buf = aws_byte_buf_from_array(output, sizeof(output));
51 output_buf.len = 0;
52 ASSERT_SUCCESS(aws_checksum_finalize(checksum, &output_buf));
53
54 uint8_t expected[] = {0x0C, 0x1A, 0x80, 0x03, 0x6D, 0x65, 0xC5, 0x55};
55 struct aws_byte_cursor expected_buf = aws_byte_cursor_from_array(expected, sizeof(expected));
56 ASSERT_BIN_ARRAYS_EQUALS(expected_buf.ptr, expected_buf.len, output_buf.buffer, output_buf.len);
57
58 aws_checksum_destroy(checksum);
59
60 aws_s3_library_clean_up();
61
62 return AWS_OP_SUCCESS;
63 }
64
65 AWS_TEST_CASE(crc64nvme_nist_test_case_3, s_crc64nvme_nist_test_case_3_fn)
66
67 static int s_crc64nvme_nist_test_case_4_fn(struct aws_allocator *allocator, void *ctx) {
68 (void)ctx;
69
70 aws_s3_library_init(allocator);
71
72 struct aws_s3_checksum *checksum = aws_checksum_new(allocator, AWS_SCA_CRC64NVME);
73 ASSERT_NOT_NULL(checksum);
74 struct aws_byte_cursor input = aws_byte_cursor_from_c_str("aa");
75
76 for (size_t i = 0; i < 5; ++i) {
77 ASSERT_SUCCESS(aws_checksum_update(checksum, &input));
78 }
79
80 uint8_t output[AWS_CRC64_LEN] = {0};
81 struct aws_byte_buf output_buf = aws_byte_buf_from_array(output, sizeof(output));
82 output_buf.len = 0;
83 ASSERT_SUCCESS(aws_checksum_finalize(checksum, &output_buf));
84
85 uint8_t expected[] = {0x0C, 0x1A, 0x80, 0x03, 0x6D, 0x65, 0xC5, 0x55};
86
87 struct aws_byte_cursor expected_buf = aws_byte_cursor_from_array(expected, sizeof(expected));
88 ASSERT_BIN_ARRAYS_EQUALS(expected_buf.ptr, expected_buf.len, output_buf.buffer, output_buf.len);
89
90 aws_checksum_destroy(checksum);
91
92 aws_s3_library_clean_up();
93
94 return AWS_OP_SUCCESS;
95 }
96
97 AWS_TEST_CASE(crc64nvme_nist_test_case_4, s_crc64nvme_nist_test_case_4_fn)
98
99 static int s_crc64nvme_test_invalid_buffer_fn(struct aws_allocator *allocator, void *ctx) {
100 (void)ctx;
101
102 aws_s3_library_init(allocator);
103
104 struct aws_byte_cursor input = aws_byte_cursor_from_c_str("abcdefghbcdefghicdefghijdefghijkefghijklfghij"
105 "klmghijklmnhijklmnoijklmnopjklmnopqklm"
106 "nopqrlmnopqrsmnopqrstnopqrstu");
107 uint8_t output[AWS_CRC64_LEN] = {0};
108 struct aws_byte_buf output_buf = aws_byte_buf_from_array(output, sizeof(output));
109 output_buf.len = 1;
110
111 ASSERT_ERROR(AWS_ERROR_SHORT_BUFFER, aws_checksum_compute(allocator, AWS_SCA_CRC64NVME, &input, &output_buf));
112
113 aws_s3_library_clean_up();
114
115 return AWS_OP_SUCCESS;
116 }
117
118 AWS_TEST_CASE(crc64nvme_test_invalid_buffer, s_crc64nvme_test_invalid_buffer_fn)
119
120 static int s_crc64nvme_test_invalid_state_fn(struct aws_allocator *allocator, void *ctx) {
121 (void)ctx;
122
123 aws_s3_library_init(allocator);
124
125 struct aws_byte_cursor input = aws_byte_cursor_from_c_str("abcdefghbcdefghicdefghijdefghijkefghijklfghij"
126 "klmghijklmnhijklmnoijklmnopjklmnopqklm"
127 "nopqrlmnopqrsmnopqrstnopqrstu");
128
129 struct aws_s3_checksum *checksum = aws_checksum_new(allocator, AWS_SCA_CRC64NVME);
130 ASSERT_NOT_NULL(checksum);
131
132 uint8_t output[AWS_CRC64_LEN] = {0};
133 struct aws_byte_buf output_buf = aws_byte_buf_from_array(output, sizeof(output));
134 output_buf.len = 0;
135
136 ASSERT_SUCCESS(aws_checksum_update(checksum, &input));
137 ASSERT_SUCCESS(aws_checksum_finalize(checksum, &output_buf));
138 ASSERT_ERROR(AWS_ERROR_INVALID_STATE, aws_checksum_update(checksum, &input));
139 ASSERT_ERROR(AWS_ERROR_INVALID_STATE, aws_checksum_finalize(checksum, &output_buf));
140
141 aws_checksum_destroy(checksum);
142
143 aws_s3_library_clean_up();
144
145 return AWS_OP_SUCCESS;
146 }
147
148 AWS_TEST_CASE(crc64nvme_test_invalid_state, s_crc64nvme_test_invalid_state_fn)