]>
git.proxmox.com Git - ceph.git/blob - ceph/src/crypto/isa-l/isa-l_crypto/md5_mb/md5_mb_rand_ssl_test.c
1 /**********************************************************************
2 Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
32 #include <openssl/md5.h>
35 #define TEST_LEN (1024*1024)
41 # define TEST_SEED 0x1234
44 /* Reference digest global to reduce stack usage */
45 static uint8_t digest_ssl
[TEST_BUFS
][4 * MD5_DIGEST_NWORDS
];
47 // Generates pseudo-random data
48 void rand_buffer(unsigned char *buf
, const long buffer_size
)
51 for (i
= 0; i
< buffer_size
; i
++)
57 MD5_HASH_CTX_MGR
*mgr
= NULL
;
58 MD5_HASH_CTX ctxpool
[TEST_BUFS
];
59 unsigned char *bufs
[TEST_BUFS
];
60 uint32_t i
, j
, fail
= 0;
61 uint32_t lens
[TEST_BUFS
];
64 printf("multibinary_md5 test, %d sets of %dx%d max: ", RANDOMS
, TEST_BUFS
, TEST_LEN
);
68 posix_memalign((void *)&mgr
, 16, sizeof(MD5_HASH_CTX_MGR
));
69 md5_ctx_mgr_init(mgr
);
71 for (i
= 0; i
< TEST_BUFS
; i
++) {
72 // Allocate and fill buffer
73 bufs
[i
] = (unsigned char *)malloc(TEST_LEN
);
74 if (bufs
[i
] == NULL
) {
75 printf("malloc failed test aborted\n");
78 rand_buffer(bufs
[i
], TEST_LEN
);
81 hash_ctx_init(&ctxpool
[i
]);
82 ctxpool
[i
].user_data
= (void *)((uint64_t) i
);
85 MD5(bufs
[i
], TEST_LEN
, digest_ssl
[i
]);
88 md5_ctx_mgr_submit(mgr
, &ctxpool
[i
], bufs
[i
], TEST_LEN
, HASH_ENTIRE
);
91 while (md5_ctx_mgr_flush(mgr
)) ;
93 for (i
= 0; i
< TEST_BUFS
; i
++) {
94 for (j
= 0; j
< MD5_DIGEST_NWORDS
; j
++) {
95 if (ctxpool
[i
].job
.result_digest
[j
] != ((uint32_t *) digest_ssl
[i
])[j
]) {
97 printf("Test%d, digest%d fail %08X <=> %08X\n",
98 i
, j
, ctxpool
[i
].job
.result_digest
[j
],
99 ((uint32_t *) digest_ssl
[i
])[j
]);
105 // Run tests with random size and number of jobs
106 for (t
= 0; t
< RANDOMS
; t
++) {
107 jobs
= rand() % (TEST_BUFS
);
109 md5_ctx_mgr_init(mgr
);
111 for (i
= 0; i
< jobs
; i
++) {
112 // Ramdom buffer with ramdom len and contents
113 lens
[i
] = rand() % (TEST_LEN
);
114 rand_buffer(bufs
[i
], lens
[i
]);
117 MD5(bufs
[i
], lens
[i
], digest_ssl
[i
]);
120 md5_ctx_mgr_submit(mgr
, &ctxpool
[i
], bufs
[i
], lens
[i
], HASH_ENTIRE
);
123 while (md5_ctx_mgr_flush(mgr
)) ;
125 for (i
= 0; i
< jobs
; i
++) {
126 for (j
= 0; j
< MD5_DIGEST_NWORDS
; j
++) {
127 if (ctxpool
[i
].job
.result_digest
[j
] !=
128 ((uint32_t *) digest_ssl
[i
])[j
]) {
130 printf("Test%d, digest%d fail %08X <=> %08X\n",
131 i
, j
, ctxpool
[i
].job
.result_digest
[j
],
132 ((uint32_t *) digest_ssl
[i
])[j
]);
137 printf("Test failed function check %d\n", fail
);
146 printf("Test failed function check %d\n", fail
);
148 printf(" multibinary_md5_ssl rand: Pass\n");