mirror of
https://github.com/darlinghq/darling-corecrypto.git
synced 2024-11-23 12:19:44 +00:00
Implement cc_print and ccdigest_oid_lookup
This commit is contained in:
parent
b9e454d7dc
commit
a06928b4bf
@ -65,6 +65,17 @@ extern int printf(const char *format, ...) __printflike(1,2);
|
||||
#include <corecrypto/cc.h>
|
||||
|
||||
/* Print a byte array of arbitrary size */
|
||||
void cc_print(const char *label, size_t count, const uint8_t *s);
|
||||
CC_INLINE
|
||||
void cc_print(const char* label, size_t count, const uint8_t* array) {
|
||||
printf("%s:", label);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
printf(" %02x", array[i]);
|
||||
};
|
||||
|
||||
CC_INLINE
|
||||
void cc_println(const char* label, size_t count, const uint8_t* array) {
|
||||
cc_print(label, count, array);
|
||||
putchar('\n');
|
||||
};
|
||||
|
||||
#endif /* _CORECRYPTO_CCN_DEBUG_H_ */
|
||||
|
@ -30,7 +30,20 @@ bool ccdigest_oid_equal(const struct ccdigest_info *di, ccoid_t oid) {
|
||||
|
||||
typedef const struct ccdigest_info *(ccdigest_lookup)(ccoid_t oid);
|
||||
|
||||
#include <stdarg.h>
|
||||
const struct ccdigest_info *ccdigest_oid_lookup(ccoid_t oid, ...);
|
||||
//#include <stdarg.h>
|
||||
|
||||
// NOTE(@facekapow):
|
||||
// i'm not sure entirely sure what Apple was going for with the varargs,
|
||||
// especially since there was no documentation in the header
|
||||
//
|
||||
// my initial assumption was that it was used to try multiple possible OIDs
|
||||
// and return the digest info for the first one that was found. (un?)fortunately,
|
||||
// there's no indication of how to determine the length of the varargs
|
||||
// (NULL could be used as the last element)
|
||||
//
|
||||
// therefore, i'm just going to remove the varargs. besides, it's in a private header
|
||||
// which means that only our own implementation should use it, so we can modify it
|
||||
// however we want
|
||||
const struct ccdigest_info *ccdigest_oid_lookup(ccoid_t oid /*, ...*/);
|
||||
|
||||
#endif /* _CORECRYPTO_CCDIGEST_PRIV_H_ */
|
||||
|
@ -18,9 +18,17 @@
|
||||
*/
|
||||
|
||||
#include <corecrypto/ccdigest.h>
|
||||
#include <corecrypto/ccdigest_priv.h>
|
||||
#include <string.h>
|
||||
#include <libkern/OSByteOrder.h>
|
||||
|
||||
#include <corecrypto/ccmd2.h>
|
||||
#include <corecrypto/ccmd4.h>
|
||||
#include <corecrypto/ccmd5.h>
|
||||
#include <corecrypto/ccsha1.h>
|
||||
#include <corecrypto/ccsha2.h>
|
||||
#include <corecrypto/ccripemd.h>
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
static uint64_t swap64le(uint64_t v) { return v; }
|
||||
#define swap64be _OSSwapInt64
|
||||
@ -201,3 +209,27 @@ int ccdigest_test_chunk_vector(const struct ccdigest_info* di, const struct ccdi
|
||||
return ccdigest_test_chunk(di, v->len, v->message, v->digest, chunk);
|
||||
}
|
||||
|
||||
|
||||
const struct ccdigest_info* ccdigest_oid_lookup(ccoid_t oid)
|
||||
{
|
||||
#define CC_OID_DI_PTR(x) &cc ## x ## _di
|
||||
#define CC_OID_DI_FUNC(x) cc ## x ## _di()
|
||||
#define CC_OID_CMP(x) if (ccdigest_oid_equal(x, oid)) { return x; }
|
||||
#define CC_OID_CMP_PTR(x) CC_OID_CMP(CC_OID_DI_PTR(x))
|
||||
#define CC_OID_CMP_FUNC(x) CC_OID_CMP(CC_OID_DI_FUNC(x))
|
||||
|
||||
CC_OID_CMP_PTR(md2);
|
||||
CC_OID_CMP_PTR(md4);
|
||||
CC_OID_CMP_FUNC(md5);
|
||||
CC_OID_CMP_FUNC(sha1);
|
||||
CC_OID_CMP_FUNC(sha224);
|
||||
CC_OID_CMP_FUNC(sha256);
|
||||
CC_OID_CMP_FUNC(sha384);
|
||||
CC_OID_CMP_FUNC(sha512);
|
||||
CC_OID_CMP_PTR(rmd128);
|
||||
CC_OID_CMP_PTR(rmd160);
|
||||
CC_OID_CMP_PTR(rmd256);
|
||||
CC_OID_CMP_PTR(rmd320);
|
||||
|
||||
return NULL;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user