]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/crypto/padding-00-mmcs.c
Security-58286.1.32.tar.gz
[apple/security.git] / OSX / sec / Security / Regressions / crypto / padding-00-mmcs.c
1 /*
2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
3 */
4
5 #include "testmore.h"
6
7 #include "SecPaddingConfigurationsPriv.h"
8 #include "shared_regressions.h"
9 #include "SecCFWrappers.h"
10
11 #define kTestTestCount 67
12
13 struct test_vector {
14 SecPaddingType type;
15 uint32_t originalSize;
16 int64_t paddedSize;
17 };
18 typedef struct test_vector test_vector_t;
19
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}
53 };
54
55 static void tests_negative(void)
56 {
57 CFErrorRef testError = NULL;
58
59 // Sanity
60 ok(SecPaddingCompute(SecPaddingTypeMMCS, 0, &testError) == 64 && testError==NULL);
61
62 // Wrong type
63 ok(SecPaddingCompute(100, 20, &testError) == -1);
64 ok(testError!=NULL);
65 CFReleaseNull(testError);
66 }
67
68 static void tests_positive(void)
69 {
70 CFErrorRef testError = NULL;
71 size_t n;
72
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);
78 ok(testError==NULL);
79 }
80 }
81
82 int padding_00_mmcs(int argc, char *const *argv)
83 {
84 plan_tests(kTestTestCount);
85
86 tests_positive();
87 tests_negative();
88
89 return 0;
90 }
91