2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
7 #include "SecPaddingConfigurationsPriv.h"
8 #include "shared_regressions.h"
9 #include "SecCFWrappers.h"
11 #define kTestTestCount 67
15 uint32_t originalSize
;
18 typedef struct test_vector test_vector_t
;
20 test_vector_t test_vectors
[] = {
21 {SecPaddingTypeMMCS
,0,64},
22 {SecPaddingTypeMMCS
,1,64},
23 {SecPaddingTypeMMCS
,2,64},
24 {SecPaddingTypeMMCS
,64,64},
25 {SecPaddingTypeMMCS
,65,128},
26 {SecPaddingTypeMMCS
,68,128},
27 {SecPaddingTypeMMCS
,80,128},
28 {SecPaddingTypeMMCS
,90,128},
29 {SecPaddingTypeMMCS
,100,128},
30 {SecPaddingTypeMMCS
,128,128},
31 {SecPaddingTypeMMCS
,129,256},
32 {SecPaddingTypeMMCS
,129,256},
33 {SecPaddingTypeMMCS
,150,256},
34 {SecPaddingTypeMMCS
,256,256},
35 {SecPaddingTypeMMCS
,257,512},
36 {SecPaddingTypeMMCS
,512,512},
37 {SecPaddingTypeMMCS
,612,1024},
38 {SecPaddingTypeMMCS
,1000,1024},
39 {SecPaddingTypeMMCS
,1024,1024},
40 {SecPaddingTypeMMCS
,1025,2048},
41 {SecPaddingTypeMMCS
,1800,2048},
42 {SecPaddingTypeMMCS
,2000,2048},
43 {SecPaddingTypeMMCS
,2047,2048},
44 {SecPaddingTypeMMCS
,2048,2048},
45 {SecPaddingTypeMMCS
,3072,3072},
46 {SecPaddingTypeMMCS
,4096,4096},
47 {SecPaddingTypeMMCS
,31744,31744},
48 {SecPaddingTypeMMCS
,31999,32768},
49 {SecPaddingTypeMMCS
,32000,32768},
50 {SecPaddingTypeMMCS
,32001,32768},
51 {SecPaddingTypeMMCS
,32769,40960},
52 {SecPaddingTypeMMCS
,4294967295,4294967296}
55 static void tests_negative(void)
57 CFErrorRef testError
= NULL
;
60 ok(SecPaddingCompute(SecPaddingTypeMMCS
, 0, &testError
) == 64 && testError
==NULL
);
63 ok(SecPaddingCompute(100, 20, &testError
) == -1);
65 CFReleaseNull(testError
);
68 static void tests_positive(void)
70 CFErrorRef testError
= NULL
;
73 n
= sizeof(test_vectors
)/sizeof(test_vectors
[0]);
74 for(size_t i
=0; i
<n
; i
++) {
75 is((SecPaddingCompute(test_vectors
[i
].type
, test_vectors
[i
].originalSize
, &testError
) + test_vectors
[i
].originalSize
),
76 test_vectors
[i
].paddedSize
, "Test # %zu, type %ld: input %u",i
,(long)test_vectors
[i
].type
,
77 test_vectors
[i
].originalSize
);
82 int padding_00_mmcs(int argc
, char *const *argv
)
84 plan_tests(kTestTestCount
);