static int ccecies_export(const int fullkey, const uint32_t options, void *out, ccec_full_ctx_t key) { int status = 0; if (ECIES_EXPORT_PUB_STANDARD == (options & ECIES_EXPORT_PUB_STANDARD)) { ccec_x963_export(fullkey, out, key); }else if (ECIES_EXPORT_PUB_COMPACT == (options & ECIES_EXPORT_PUB_COMPACT)){ ccec_compact_export(fullkey, out, key); } else{ status=-2; } return status; }
static SecKeyRef ccec2SecKey(ccec_full_ctx_t fk) { size_t export_size = ccec_x963_export_size(1, fk); uint8_t export_keybytes[export_size]; ccec_x963_export(1, export_keybytes, fk); CFDataRef exportedkey = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, export_keybytes, export_size, kCFAllocatorNull); CFDictionaryRef keyattributes = CFDictionaryCreateForCFTypes(kCFAllocatorDefault, kSecValueData, exportedkey, kSecAttrKeyType, kSecAttrKeyTypeEC, kSecAttrKeyClass, kSecAttrKeyClassPrivate, NULL); SecKeyRef retval = SecKeyCreateFromAttributeDictionary(keyattributes); CFRelease(keyattributes); CFRelease(exportedkey); bzero(export_keybytes, 0); return retval; }