1/* 2 * Copyright (c) 2005-2007,2011,2014 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24 25/* 26 * DER_Keys.h - support for decoding RSA keys 27 * 28 */ 29 30#ifndef _DER_KEYS_H_ 31#define _DER_KEYS_H_ 32 33#ifdef __cplusplus 34extern "C" { 35#endif 36 37#include <libDER/libDER.h> 38#include <libDER/DER_Decode.h> 39 40/* Algorithm Identifier components */ 41typedef struct { 42 DERItem oid; /* OID */ 43 DERItem params; /* ASN_ANY, optional, DER_DEC_SAVE_DER */ 44} DERAlgorithmId; 45 46/* DERItemSpecs to decode into a DERAlgorithmId */ 47extern const DERItemSpec DERAlgorithmIdItemSpecs[]; 48extern const DERSize DERNumAlgorithmIdItemSpecs; 49 50/* X509 SubjectPublicKeyInfo */ 51typedef struct { 52 DERItem algId; /* sequence, DERAlgorithmId */ 53 DERItem pubKey; /* BIT STRING */ 54} DERSubjPubKeyInfo; 55 56/* DERItemSpecs to decode into a DERSubjPubKeyInfo */ 57extern const DERItemSpec DERSubjPubKeyInfoItemSpecs[]; 58extern const DERSize DERNumSubjPubKeyInfoItemSpecs; 59 60/* 61 * RSA public key in PKCS1 format; this is inside the BIT_STRING in 62 * DERSubjPubKeyInfo.pubKey. 63 */ 64typedef struct { 65 DERItem modulus; /* n - INTEGER */ 66 DERItem pubExponent; /* e - INTEGER */ 67} DERRSAPubKeyPKCS1; 68 69/* DERItemSpecs to decode/encode into/from a DERRSAPubKeyPKCS1 */ 70extern const DERItemSpec DERRSAPubKeyPKCS1ItemSpecs[]; 71extern const DERSize DERNumRSAPubKeyPKCS1ItemSpecs; 72 73/* 74 * RSA public key in custom (to this library) format, including 75 * the reciprocal. All fields are integers. 76 */ 77typedef struct { 78 DERItem modulus; /* n */ 79 DERItem reciprocal; /* reciprocal of modulus */ 80 DERItem pubExponent; /* e */ 81} DERRSAPubKeyApple; 82 83/* DERItemSpecs to decode/encode into/from a DERRSAPubKeyApple */ 84extern const DERItemSpec DERRSAPubKeyAppleItemSpecs[]; 85extern const DERSize DERNumRSAPubKeyAppleItemSpecs; 86 87/* 88 * RSA Private key, PKCS1 format, CRT option. 89 * All fields are integers. 90 */ 91typedef struct { 92 DERItem p; /* p * q = n */ 93 DERItem q; 94 DERItem dp; /* d mod (p-1) */ 95 DERItem dq; /* d mod (q-1) */ 96 DERItem qInv; 97} DERRSAPrivKeyCRT; 98 99/* DERItemSpecs to decode into a DERRSAPrivKeyCRT */ 100extern const DERItemSpec DERRSAPrivKeyCRTItemSpecs[]; 101extern const DERSize DERNumRSAPrivKeyCRTItemSpecs; 102 103/* Fully formed RSA key pair, for generating a PKCS1 private key */ 104typedef struct { 105 DERItem version; 106 DERItem n; /* modulus */ 107 DERItem e; /* public exponent */ 108 DERItem d; /* private exponent */ 109 DERItem p; /* n = p*q */ 110 DERItem q; 111 DERItem dp; /* d mod (p-1) */ 112 DERItem dq; /* d mod (q-1) */ 113 DERItem qInv; /* q^(-1) mod p */ 114} DERRSAKeyPair; 115 116/* DERItemSpecs to encode a DERRSAKeyPair */ 117extern const DERItemSpec DERRSAKeyPairItemSpecs[]; 118extern const DERSize DERNumRSAKeyPairItemSpecs; 119 120#ifdef __cplusplus 121} 122#endif 123 124#endif /* _DER_KEYS_H_ */ 125 126