Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1446 lines
46 KiB

  1. /* Copyright (C) Microsoft Corporation, 1996 - 1999 All rights reserved. */
  2. /* ASN.1 definitions for PFXPKCS */
  3. #include <windows.h>
  4. #include "pfxpkcs.h"
  5. ASN1module_t PFXPKCS_Module = NULL;
  6. static int ASN1CALL ASN1Enc_ObjectIdentifierType(ASN1encoding_t enc, ASN1uint32_t tag, ObjectIdentifierType *val);
  7. static int ASN1CALL ASN1Enc_OctetStringType(ASN1encoding_t enc, ASN1uint32_t tag, OctetStringType *val);
  8. static int ASN1CALL ASN1Enc_IntegerType(ASN1encoding_t enc, ASN1uint32_t tag, IntegerType *val);
  9. static int ASN1CALL ASN1Enc_RSAPublicKey(ASN1encoding_t enc, ASN1uint32_t tag, RSAPublicKey *val);
  10. static int ASN1CALL ASN1Enc_RSAPrivateKey(ASN1encoding_t enc, ASN1uint32_t tag, RSAPrivateKey *val);
  11. static int ASN1CALL ASN1Enc_AlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifier *val);
  12. static int ASN1CALL ASN1Enc_PBEParameter(ASN1encoding_t enc, ASN1uint32_t tag, PBEParameter *val);
  13. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifier *val);
  14. static int ASN1CALL ASN1Enc_AttributeSetValue(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValue *val);
  15. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val);
  16. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val);
  17. static int ASN1CALL ASN1Enc_ContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfo *val);
  18. static int ASN1CALL ASN1Enc_AuthenticatedSafes(ASN1encoding_t enc, ASN1uint32_t tag, AuthenticatedSafes *val);
  19. static int ASN1CALL ASN1Enc_SafeContents(ASN1encoding_t enc, ASN1uint32_t tag, SafeContents *val);
  20. static int ASN1CALL ASN1Enc_SafeBag(ASN1encoding_t enc, ASN1uint32_t tag, SafeBag *val);
  21. static int ASN1CALL ASN1Enc_CertBag(ASN1encoding_t enc, ASN1uint32_t tag, CertBag *val);
  22. static int ASN1CALL ASN1Enc_CRLBag(ASN1encoding_t enc, ASN1uint32_t tag, CRLBag *val);
  23. static int ASN1CALL ASN1Enc_SecretBag(ASN1encoding_t enc, ASN1uint32_t tag, SecretBag *val);
  24. static int ASN1CALL ASN1Enc_PrivateKeyAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val);
  25. static int ASN1CALL ASN1Enc_EncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val);
  26. static int ASN1CALL ASN1Enc_ContentEncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val);
  27. static int ASN1CALL ASN1Enc_DigestInfo(ASN1encoding_t enc, ASN1uint32_t tag, DigestInfo *val);
  28. static int ASN1CALL ASN1Enc_MacData(ASN1encoding_t enc, ASN1uint32_t tag, MacData *val);
  29. static int ASN1CALL ASN1Enc_PrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyInfo *val);
  30. static int ASN1CALL ASN1Enc_EncryptedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedContentInfo *val);
  31. static int ASN1CALL ASN1Enc_PFX(ASN1encoding_t enc, ASN1uint32_t tag, PFX *val);
  32. static int ASN1CALL ASN1Enc_KeyBag(ASN1encoding_t enc, ASN1uint32_t tag, KeyBag *val);
  33. static int ASN1CALL ASN1Enc_EncryptedData(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedData *val);
  34. static int ASN1CALL ASN1Enc_EncryptedPrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val);
  35. static int ASN1CALL ASN1Enc_Pkcs_8ShroudedKeyBag(ASN1encoding_t enc, ASN1uint32_t tag, Pkcs_8ShroudedKeyBag *val);
  36. static int ASN1CALL ASN1Dec_ObjectIdentifierType(ASN1decoding_t dec, ASN1uint32_t tag, ObjectIdentifierType *val);
  37. static int ASN1CALL ASN1Dec_OctetStringType(ASN1decoding_t dec, ASN1uint32_t tag, OctetStringType *val);
  38. static int ASN1CALL ASN1Dec_IntegerType(ASN1decoding_t dec, ASN1uint32_t tag, IntegerType *val);
  39. static int ASN1CALL ASN1Dec_RSAPublicKey(ASN1decoding_t dec, ASN1uint32_t tag, RSAPublicKey *val);
  40. static int ASN1CALL ASN1Dec_RSAPrivateKey(ASN1decoding_t dec, ASN1uint32_t tag, RSAPrivateKey *val);
  41. static int ASN1CALL ASN1Dec_AlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifier *val);
  42. static int ASN1CALL ASN1Dec_PBEParameter(ASN1decoding_t dec, ASN1uint32_t tag, PBEParameter *val);
  43. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifier *val);
  44. static int ASN1CALL ASN1Dec_AttributeSetValue(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValue *val);
  45. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val);
  46. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val);
  47. static int ASN1CALL ASN1Dec_ContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfo *val);
  48. static int ASN1CALL ASN1Dec_AuthenticatedSafes(ASN1decoding_t dec, ASN1uint32_t tag, AuthenticatedSafes *val);
  49. static int ASN1CALL ASN1Dec_SafeContents(ASN1decoding_t dec, ASN1uint32_t tag, SafeContents *val);
  50. static int ASN1CALL ASN1Dec_SafeBag(ASN1decoding_t dec, ASN1uint32_t tag, SafeBag *val);
  51. static int ASN1CALL ASN1Dec_CertBag(ASN1decoding_t dec, ASN1uint32_t tag, CertBag *val);
  52. static int ASN1CALL ASN1Dec_CRLBag(ASN1decoding_t dec, ASN1uint32_t tag, CRLBag *val);
  53. static int ASN1CALL ASN1Dec_SecretBag(ASN1decoding_t dec, ASN1uint32_t tag, SecretBag *val);
  54. static int ASN1CALL ASN1Dec_PrivateKeyAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val);
  55. static int ASN1CALL ASN1Dec_EncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val);
  56. static int ASN1CALL ASN1Dec_ContentEncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val);
  57. static int ASN1CALL ASN1Dec_DigestInfo(ASN1decoding_t dec, ASN1uint32_t tag, DigestInfo *val);
  58. static int ASN1CALL ASN1Dec_MacData(ASN1decoding_t dec, ASN1uint32_t tag, MacData *val);
  59. static int ASN1CALL ASN1Dec_PrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyInfo *val);
  60. static int ASN1CALL ASN1Dec_EncryptedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedContentInfo *val);
  61. static int ASN1CALL ASN1Dec_PFX(ASN1decoding_t dec, ASN1uint32_t tag, PFX *val);
  62. static int ASN1CALL ASN1Dec_KeyBag(ASN1decoding_t dec, ASN1uint32_t tag, KeyBag *val);
  63. static int ASN1CALL ASN1Dec_EncryptedData(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedData *val);
  64. static int ASN1CALL ASN1Dec_EncryptedPrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val);
  65. static int ASN1CALL ASN1Dec_Pkcs_8ShroudedKeyBag(ASN1decoding_t dec, ASN1uint32_t tag, Pkcs_8ShroudedKeyBag *val);
  66. static void ASN1CALL ASN1Free_ObjectIdentifierType(ObjectIdentifierType *val);
  67. static void ASN1CALL ASN1Free_OctetStringType(OctetStringType *val);
  68. static void ASN1CALL ASN1Free_IntegerType(IntegerType *val);
  69. static void ASN1CALL ASN1Free_RSAPublicKey(RSAPublicKey *val);
  70. static void ASN1CALL ASN1Free_RSAPrivateKey(RSAPrivateKey *val);
  71. static void ASN1CALL ASN1Free_AlgorithmIdentifier(AlgorithmIdentifier *val);
  72. static void ASN1CALL ASN1Free_PBEParameter(PBEParameter *val);
  73. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifier(DigestAlgorithmIdentifier *val);
  74. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val);
  75. static void ASN1CALL ASN1Free_Attribute(Attribute *val);
  76. static void ASN1CALL ASN1Free_Attributes(Attributes *val);
  77. static void ASN1CALL ASN1Free_ContentInfo(ContentInfo *val);
  78. static void ASN1CALL ASN1Free_AuthenticatedSafes(AuthenticatedSafes *val);
  79. static void ASN1CALL ASN1Free_SafeContents(SafeContents *val);
  80. static void ASN1CALL ASN1Free_SafeBag(SafeBag *val);
  81. static void ASN1CALL ASN1Free_CertBag(CertBag *val);
  82. static void ASN1CALL ASN1Free_CRLBag(CRLBag *val);
  83. static void ASN1CALL ASN1Free_SecretBag(SecretBag *val);
  84. static void ASN1CALL ASN1Free_PrivateKeyAlgorithmIdentifier(PrivateKeyAlgorithmIdentifier *val);
  85. static void ASN1CALL ASN1Free_EncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier *val);
  86. static void ASN1CALL ASN1Free_ContentEncryptionAlgorithmIdentifier(ContentEncryptionAlgorithmIdentifier *val);
  87. static void ASN1CALL ASN1Free_DigestInfo(DigestInfo *val);
  88. static void ASN1CALL ASN1Free_MacData(MacData *val);
  89. static void ASN1CALL ASN1Free_PrivateKeyInfo(PrivateKeyInfo *val);
  90. static void ASN1CALL ASN1Free_EncryptedContentInfo(EncryptedContentInfo *val);
  91. static void ASN1CALL ASN1Free_PFX(PFX *val);
  92. static void ASN1CALL ASN1Free_KeyBag(KeyBag *val);
  93. static void ASN1CALL ASN1Free_EncryptedData(EncryptedData *val);
  94. static void ASN1CALL ASN1Free_EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo *val);
  95. static void ASN1CALL ASN1Free_Pkcs_8ShroudedKeyBag(Pkcs_8ShroudedKeyBag *val);
  96. typedef ASN1BerEncFun_t ASN1EncFun_t;
  97. static const ASN1EncFun_t encfntab[22] = {
  98. (ASN1EncFun_t) ASN1Enc_ObjectIdentifierType,
  99. (ASN1EncFun_t) ASN1Enc_OctetStringType,
  100. (ASN1EncFun_t) ASN1Enc_IntegerType,
  101. (ASN1EncFun_t) ASN1Enc_RSAPublicKey,
  102. (ASN1EncFun_t) ASN1Enc_RSAPrivateKey,
  103. (ASN1EncFun_t) ASN1Enc_PBEParameter,
  104. (ASN1EncFun_t) ASN1Enc_AttributeSetValue,
  105. (ASN1EncFun_t) ASN1Enc_Attributes,
  106. (ASN1EncFun_t) ASN1Enc_AuthenticatedSafes,
  107. (ASN1EncFun_t) ASN1Enc_SafeContents,
  108. (ASN1EncFun_t) ASN1Enc_SafeBag,
  109. (ASN1EncFun_t) ASN1Enc_CertBag,
  110. (ASN1EncFun_t) ASN1Enc_CRLBag,
  111. (ASN1EncFun_t) ASN1Enc_SecretBag,
  112. (ASN1EncFun_t) ASN1Enc_DigestInfo,
  113. (ASN1EncFun_t) ASN1Enc_MacData,
  114. (ASN1EncFun_t) ASN1Enc_PrivateKeyInfo,
  115. (ASN1EncFun_t) ASN1Enc_PFX,
  116. (ASN1EncFun_t) ASN1Enc_KeyBag,
  117. (ASN1EncFun_t) ASN1Enc_EncryptedData,
  118. (ASN1EncFun_t) ASN1Enc_EncryptedPrivateKeyInfo,
  119. (ASN1EncFun_t) ASN1Enc_Pkcs_8ShroudedKeyBag,
  120. };
  121. typedef ASN1BerDecFun_t ASN1DecFun_t;
  122. static const ASN1DecFun_t decfntab[22] = {
  123. (ASN1DecFun_t) ASN1Dec_ObjectIdentifierType,
  124. (ASN1DecFun_t) ASN1Dec_OctetStringType,
  125. (ASN1DecFun_t) ASN1Dec_IntegerType,
  126. (ASN1DecFun_t) ASN1Dec_RSAPublicKey,
  127. (ASN1DecFun_t) ASN1Dec_RSAPrivateKey,
  128. (ASN1DecFun_t) ASN1Dec_PBEParameter,
  129. (ASN1DecFun_t) ASN1Dec_AttributeSetValue,
  130. (ASN1DecFun_t) ASN1Dec_Attributes,
  131. (ASN1DecFun_t) ASN1Dec_AuthenticatedSafes,
  132. (ASN1DecFun_t) ASN1Dec_SafeContents,
  133. (ASN1DecFun_t) ASN1Dec_SafeBag,
  134. (ASN1DecFun_t) ASN1Dec_CertBag,
  135. (ASN1DecFun_t) ASN1Dec_CRLBag,
  136. (ASN1DecFun_t) ASN1Dec_SecretBag,
  137. (ASN1DecFun_t) ASN1Dec_DigestInfo,
  138. (ASN1DecFun_t) ASN1Dec_MacData,
  139. (ASN1DecFun_t) ASN1Dec_PrivateKeyInfo,
  140. (ASN1DecFun_t) ASN1Dec_PFX,
  141. (ASN1DecFun_t) ASN1Dec_KeyBag,
  142. (ASN1DecFun_t) ASN1Dec_EncryptedData,
  143. (ASN1DecFun_t) ASN1Dec_EncryptedPrivateKeyInfo,
  144. (ASN1DecFun_t) ASN1Dec_Pkcs_8ShroudedKeyBag,
  145. };
  146. static const ASN1FreeFun_t freefntab[22] = {
  147. (ASN1FreeFun_t) ASN1Free_ObjectIdentifierType,
  148. (ASN1FreeFun_t) ASN1Free_OctetStringType,
  149. (ASN1FreeFun_t) ASN1Free_IntegerType,
  150. (ASN1FreeFun_t) ASN1Free_RSAPublicKey,
  151. (ASN1FreeFun_t) ASN1Free_RSAPrivateKey,
  152. (ASN1FreeFun_t) ASN1Free_PBEParameter,
  153. (ASN1FreeFun_t) ASN1Free_AttributeSetValue,
  154. (ASN1FreeFun_t) ASN1Free_Attributes,
  155. (ASN1FreeFun_t) ASN1Free_AuthenticatedSafes,
  156. (ASN1FreeFun_t) ASN1Free_SafeContents,
  157. (ASN1FreeFun_t) ASN1Free_SafeBag,
  158. (ASN1FreeFun_t) ASN1Free_CertBag,
  159. (ASN1FreeFun_t) ASN1Free_CRLBag,
  160. (ASN1FreeFun_t) ASN1Free_SecretBag,
  161. (ASN1FreeFun_t) ASN1Free_DigestInfo,
  162. (ASN1FreeFun_t) ASN1Free_MacData,
  163. (ASN1FreeFun_t) ASN1Free_PrivateKeyInfo,
  164. (ASN1FreeFun_t) ASN1Free_PFX,
  165. (ASN1FreeFun_t) ASN1Free_KeyBag,
  166. (ASN1FreeFun_t) ASN1Free_EncryptedData,
  167. (ASN1FreeFun_t) ASN1Free_EncryptedPrivateKeyInfo,
  168. (ASN1FreeFun_t) ASN1Free_Pkcs_8ShroudedKeyBag,
  169. };
  170. static const ULONG sizetab[22] = {
  171. SIZE_PFXPKCS_Module_PDU_0,
  172. SIZE_PFXPKCS_Module_PDU_1,
  173. SIZE_PFXPKCS_Module_PDU_2,
  174. SIZE_PFXPKCS_Module_PDU_3,
  175. SIZE_PFXPKCS_Module_PDU_4,
  176. SIZE_PFXPKCS_Module_PDU_5,
  177. SIZE_PFXPKCS_Module_PDU_6,
  178. SIZE_PFXPKCS_Module_PDU_7,
  179. SIZE_PFXPKCS_Module_PDU_8,
  180. SIZE_PFXPKCS_Module_PDU_9,
  181. SIZE_PFXPKCS_Module_PDU_10,
  182. SIZE_PFXPKCS_Module_PDU_11,
  183. SIZE_PFXPKCS_Module_PDU_12,
  184. SIZE_PFXPKCS_Module_PDU_13,
  185. SIZE_PFXPKCS_Module_PDU_14,
  186. SIZE_PFXPKCS_Module_PDU_15,
  187. SIZE_PFXPKCS_Module_PDU_16,
  188. SIZE_PFXPKCS_Module_PDU_17,
  189. SIZE_PFXPKCS_Module_PDU_18,
  190. SIZE_PFXPKCS_Module_PDU_19,
  191. SIZE_PFXPKCS_Module_PDU_20,
  192. SIZE_PFXPKCS_Module_PDU_21,
  193. };
  194. /* forward declarations of values: */
  195. /* definitions of value components: */
  196. /* definitions of values: */
  197. ASN1int32_t MacData_macIterationCount_default = 1;
  198. void ASN1CALL PFXPKCS_Module_Startup(void)
  199. {
  200. PFXPKCS_Module = ASN1_CreateModule(0x10000, ASN1_BER_RULE_DER, ASN1FLAGS_NOASSERT, 22, (const ASN1GenericFun_t *) encfntab, (const ASN1GenericFun_t *) decfntab, freefntab, sizetab, 0x70786670);
  201. }
  202. void ASN1CALL PFXPKCS_Module_Cleanup(void)
  203. {
  204. ASN1_CloseModule(PFXPKCS_Module);
  205. PFXPKCS_Module = NULL;
  206. }
  207. static int ASN1CALL ASN1Enc_ObjectIdentifierType(ASN1encoding_t enc, ASN1uint32_t tag, ObjectIdentifierType *val)
  208. {
  209. if (!ASN1BEREncObjectIdentifier2(enc, tag ? tag : 0x6, val))
  210. return 0;
  211. return 1;
  212. }
  213. static int ASN1CALL ASN1Dec_ObjectIdentifierType(ASN1decoding_t dec, ASN1uint32_t tag, ObjectIdentifierType *val)
  214. {
  215. if (!ASN1BERDecObjectIdentifier2(dec, tag ? tag : 0x6, val))
  216. return 0;
  217. return 1;
  218. }
  219. static void ASN1CALL ASN1Free_ObjectIdentifierType(ObjectIdentifierType *val)
  220. {
  221. if (val) {
  222. }
  223. }
  224. static int ASN1CALL ASN1Enc_OctetStringType(ASN1encoding_t enc, ASN1uint32_t tag, OctetStringType *val)
  225. {
  226. if (!ASN1DEREncOctetString(enc, tag ? tag : 0x4, (val)->length, (val)->value))
  227. return 0;
  228. return 1;
  229. }
  230. static int ASN1CALL ASN1Dec_OctetStringType(ASN1decoding_t dec, ASN1uint32_t tag, OctetStringType *val)
  231. {
  232. if (!ASN1BERDecOctetString(dec, tag ? tag : 0x4, val))
  233. return 0;
  234. return 1;
  235. }
  236. static void ASN1CALL ASN1Free_OctetStringType(OctetStringType *val)
  237. {
  238. if (val) {
  239. ASN1octetstring_free(val);
  240. }
  241. }
  242. static int ASN1CALL ASN1Enc_IntegerType(ASN1encoding_t enc, ASN1uint32_t tag, IntegerType *val)
  243. {
  244. if (!ASN1BEREncSX(enc, tag ? tag : 0x2, val))
  245. return 0;
  246. return 1;
  247. }
  248. static int ASN1CALL ASN1Dec_IntegerType(ASN1decoding_t dec, ASN1uint32_t tag, IntegerType *val)
  249. {
  250. if (!ASN1BERDecSXVal(dec, tag ? tag : 0x2, val))
  251. return 0;
  252. return 1;
  253. }
  254. static void ASN1CALL ASN1Free_IntegerType(IntegerType *val)
  255. {
  256. if (val) {
  257. ASN1intx_free(val);
  258. }
  259. }
  260. static int ASN1CALL ASN1Enc_RSAPublicKey(ASN1encoding_t enc, ASN1uint32_t tag, RSAPublicKey *val)
  261. {
  262. ASN1uint32_t nLenOff;
  263. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  264. return 0;
  265. if (!ASN1BEREncSX(enc, 0x2, &(val)->modulus))
  266. return 0;
  267. if (!ASN1BEREncSX(enc, 0x2, &(val)->publicExponent))
  268. return 0;
  269. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  270. return 0;
  271. return 1;
  272. }
  273. static int ASN1CALL ASN1Dec_RSAPublicKey(ASN1decoding_t dec, ASN1uint32_t tag, RSAPublicKey *val)
  274. {
  275. ASN1decoding_t dd;
  276. ASN1octet_t *di;
  277. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  278. return 0;
  279. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->modulus))
  280. return 0;
  281. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->publicExponent))
  282. return 0;
  283. if (!ASN1BERDecEndOfContents(dec, dd, di))
  284. return 0;
  285. return 1;
  286. }
  287. static void ASN1CALL ASN1Free_RSAPublicKey(RSAPublicKey *val)
  288. {
  289. if (val) {
  290. ASN1intx_free(&(val)->modulus);
  291. ASN1intx_free(&(val)->publicExponent);
  292. }
  293. }
  294. static int ASN1CALL ASN1Enc_RSAPrivateKey(ASN1encoding_t enc, ASN1uint32_t tag, RSAPrivateKey *val)
  295. {
  296. ASN1uint32_t nLenOff;
  297. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  298. return 0;
  299. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  300. return 0;
  301. if (!ASN1BEREncSX(enc, 0x2, &(val)->modulus))
  302. return 0;
  303. if (!ASN1BEREncS32(enc, 0x2, (val)->publicExponent))
  304. return 0;
  305. if (!ASN1BEREncSX(enc, 0x2, &(val)->privateExponent))
  306. return 0;
  307. if (!ASN1BEREncSX(enc, 0x2, &(val)->prime1))
  308. return 0;
  309. if (!ASN1BEREncSX(enc, 0x2, &(val)->prime2))
  310. return 0;
  311. if (!ASN1BEREncSX(enc, 0x2, &(val)->exponent1))
  312. return 0;
  313. if (!ASN1BEREncSX(enc, 0x2, &(val)->exponent2))
  314. return 0;
  315. if (!ASN1BEREncSX(enc, 0x2, &(val)->coefficient))
  316. return 0;
  317. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  318. return 0;
  319. return 1;
  320. }
  321. static int ASN1CALL ASN1Dec_RSAPrivateKey(ASN1decoding_t dec, ASN1uint32_t tag, RSAPrivateKey *val)
  322. {
  323. ASN1decoding_t dd;
  324. ASN1octet_t *di;
  325. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  326. return 0;
  327. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  328. return 0;
  329. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->modulus))
  330. return 0;
  331. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->publicExponent))
  332. return 0;
  333. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->privateExponent))
  334. return 0;
  335. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->prime1))
  336. return 0;
  337. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->prime2))
  338. return 0;
  339. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->exponent1))
  340. return 0;
  341. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->exponent2))
  342. return 0;
  343. if (!ASN1BERDecSXVal(dd, 0x2, &(val)->coefficient))
  344. return 0;
  345. if (!ASN1BERDecEndOfContents(dec, dd, di))
  346. return 0;
  347. return 1;
  348. }
  349. static void ASN1CALL ASN1Free_RSAPrivateKey(RSAPrivateKey *val)
  350. {
  351. if (val) {
  352. ASN1intx_free(&(val)->modulus);
  353. ASN1intx_free(&(val)->privateExponent);
  354. ASN1intx_free(&(val)->prime1);
  355. ASN1intx_free(&(val)->prime2);
  356. ASN1intx_free(&(val)->exponent1);
  357. ASN1intx_free(&(val)->exponent2);
  358. ASN1intx_free(&(val)->coefficient);
  359. }
  360. }
  361. static int ASN1CALL ASN1Enc_AlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, AlgorithmIdentifier *val)
  362. {
  363. ASN1uint32_t nLenOff;
  364. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  365. return 0;
  366. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->algorithm))
  367. return 0;
  368. if ((val)->o[0] & 0x80) {
  369. if (!ASN1BEREncOpenType(enc, &(val)->parameters))
  370. return 0;
  371. }
  372. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  373. return 0;
  374. return 1;
  375. }
  376. static int ASN1CALL ASN1Dec_AlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, AlgorithmIdentifier *val)
  377. {
  378. ASN1decoding_t dd;
  379. ASN1octet_t *di;
  380. ASN1uint32_t t;
  381. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  382. return 0;
  383. ZeroMemory((val)->o, 1);
  384. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->algorithm))
  385. return 0;
  386. if (ASN1BERDecPeekTag(dd, &t)) {
  387. (val)->o[0] |= 0x80;
  388. if (!ASN1BERDecOpenType(dd, &(val)->parameters))
  389. return 0;
  390. }
  391. if (!ASN1BERDecEndOfContents(dec, dd, di))
  392. return 0;
  393. return 1;
  394. }
  395. static void ASN1CALL ASN1Free_AlgorithmIdentifier(AlgorithmIdentifier *val)
  396. {
  397. if (val) {
  398. if ((val)->o[0] & 0x80) {
  399. ASN1open_free(&(val)->parameters);
  400. }
  401. }
  402. }
  403. static int ASN1CALL ASN1Enc_PBEParameter(ASN1encoding_t enc, ASN1uint32_t tag, PBEParameter *val)
  404. {
  405. ASN1uint32_t nLenOff;
  406. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  407. return 0;
  408. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->salt).length, ((val)->salt).value))
  409. return 0;
  410. if (!ASN1BEREncS32(enc, 0x2, (val)->iterationCount))
  411. return 0;
  412. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  413. return 0;
  414. return 1;
  415. }
  416. static int ASN1CALL ASN1Dec_PBEParameter(ASN1decoding_t dec, ASN1uint32_t tag, PBEParameter *val)
  417. {
  418. ASN1decoding_t dd;
  419. ASN1octet_t *di;
  420. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  421. return 0;
  422. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->salt))
  423. return 0;
  424. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->iterationCount))
  425. return 0;
  426. if (!ASN1BERDecEndOfContents(dec, dd, di))
  427. return 0;
  428. return 1;
  429. }
  430. static void ASN1CALL ASN1Free_PBEParameter(PBEParameter *val)
  431. {
  432. if (val) {
  433. ASN1octetstring_free(&(val)->salt);
  434. }
  435. }
  436. static int ASN1CALL ASN1Enc_DigestAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, DigestAlgorithmIdentifier *val)
  437. {
  438. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  439. return 0;
  440. return 1;
  441. }
  442. static int ASN1CALL ASN1Dec_DigestAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, DigestAlgorithmIdentifier *val)
  443. {
  444. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  445. return 0;
  446. return 1;
  447. }
  448. static void ASN1CALL ASN1Free_DigestAlgorithmIdentifier(DigestAlgorithmIdentifier *val)
  449. {
  450. if (val) {
  451. ASN1Free_AlgorithmIdentifier(val);
  452. }
  453. }
  454. static int ASN1CALL ASN1Enc_AttributeSetValue(ASN1encoding_t enc, ASN1uint32_t tag, AttributeSetValue *val)
  455. {
  456. ASN1uint32_t nLenOff;
  457. void *pBlk;
  458. ASN1uint32_t i;
  459. ASN1encoding_t enc2;
  460. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  461. return 0;
  462. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  463. return 0;
  464. for (i = 0; i < (val)->count; i++) {
  465. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  466. return 0;
  467. if (!ASN1BEREncOpenType(enc2, &((val)->value)[i]))
  468. return 0;
  469. if (!ASN1DEREncFlushBlkElement(pBlk))
  470. return 0;
  471. }
  472. if (!ASN1DEREncEndBlk(pBlk))
  473. return 0;
  474. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  475. return 0;
  476. return 1;
  477. }
  478. static int ASN1CALL ASN1Dec_AttributeSetValue(ASN1decoding_t dec, ASN1uint32_t tag, AttributeSetValue *val)
  479. {
  480. ASN1decoding_t dd;
  481. ASN1octet_t *di;
  482. ASN1uint32_t t;
  483. ASN1uint32_t n;
  484. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  485. return 0;
  486. (val)->count = n = 0;
  487. (val)->value = NULL;
  488. while (ASN1BERDecNotEndOfContents(dd, di)) {
  489. if (!ASN1BERDecPeekTag(dd, &t))
  490. return 0;
  491. if ((val)->count >= n) {
  492. n = n ? (n << 1) : 16;
  493. if (!((val)->value = (AttributeSetValue_Set *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  494. return 0;
  495. }
  496. if (!ASN1BERDecOpenType(dd, &((val)->value)[(val)->count]))
  497. return 0;
  498. ((val)->count)++;
  499. }
  500. if (!ASN1BERDecEndOfContents(dec, dd, di))
  501. return 0;
  502. return 1;
  503. }
  504. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val)
  505. {
  506. ASN1uint32_t i;
  507. if (val) {
  508. ASN1open_free(&(val)->value[0]);
  509. for (i = 1; i < (val)->count; i++) {
  510. ASN1open_free(&(val)->value[i]);
  511. }
  512. ASN1Free((val)->value);
  513. }
  514. }
  515. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val)
  516. {
  517. ASN1uint32_t nLenOff;
  518. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  519. return 0;
  520. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->attributeType))
  521. return 0;
  522. if (!ASN1Enc_AttributeSetValue(enc, 0, &(val)->attributeValue))
  523. return 0;
  524. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  525. return 0;
  526. return 1;
  527. }
  528. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val)
  529. {
  530. ASN1decoding_t dd;
  531. ASN1octet_t *di;
  532. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  533. return 0;
  534. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->attributeType))
  535. return 0;
  536. if (!ASN1Dec_AttributeSetValue(dd, 0, &(val)->attributeValue))
  537. return 0;
  538. if (!ASN1BERDecEndOfContents(dec, dd, di))
  539. return 0;
  540. return 1;
  541. }
  542. static void ASN1CALL ASN1Free_Attribute(Attribute *val)
  543. {
  544. if (val) {
  545. ASN1Free_AttributeSetValue(&(val)->attributeValue);
  546. }
  547. }
  548. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val)
  549. {
  550. ASN1uint32_t nLenOff;
  551. void *pBlk;
  552. ASN1uint32_t i;
  553. ASN1encoding_t enc2;
  554. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  555. return 0;
  556. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  557. return 0;
  558. for (i = 0; i < (val)->count; i++) {
  559. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  560. return 0;
  561. if (!ASN1Enc_Attribute(enc2, 0, &((val)->value)[i]))
  562. return 0;
  563. if (!ASN1DEREncFlushBlkElement(pBlk))
  564. return 0;
  565. }
  566. if (!ASN1DEREncEndBlk(pBlk))
  567. return 0;
  568. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  569. return 0;
  570. return 1;
  571. }
  572. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val)
  573. {
  574. ASN1decoding_t dd;
  575. ASN1octet_t *di;
  576. ASN1uint32_t t;
  577. ASN1uint32_t n;
  578. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  579. return 0;
  580. (val)->count = n = 0;
  581. (val)->value = NULL;
  582. while (ASN1BERDecNotEndOfContents(dd, di)) {
  583. if (!ASN1BERDecPeekTag(dd, &t))
  584. return 0;
  585. if ((val)->count >= n) {
  586. n = n ? (n << 1) : 16;
  587. if (!((val)->value = (Attribute *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  588. return 0;
  589. }
  590. if (!ASN1Dec_Attribute(dd, 0, &((val)->value)[(val)->count]))
  591. return 0;
  592. ((val)->count)++;
  593. }
  594. if (!ASN1BERDecEndOfContents(dec, dd, di))
  595. return 0;
  596. return 1;
  597. }
  598. static void ASN1CALL ASN1Free_Attributes(Attributes *val)
  599. {
  600. ASN1uint32_t i;
  601. if (val) {
  602. ASN1Free_Attribute(&(val)->value[0]);
  603. for (i = 1; i < (val)->count; i++) {
  604. ASN1Free_Attribute(&(val)->value[i]);
  605. }
  606. ASN1Free((val)->value);
  607. }
  608. }
  609. static int ASN1CALL ASN1Enc_ContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfo *val)
  610. {
  611. ASN1uint32_t nLenOff;
  612. ASN1uint32_t nLenOff0;
  613. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  614. return 0;
  615. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  616. return 0;
  617. if ((val)->o[0] & 0x80) {
  618. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  619. return 0;
  620. if (!ASN1BEREncOpenType(enc, &(val)->content))
  621. return 0;
  622. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  623. return 0;
  624. }
  625. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  626. return 0;
  627. return 1;
  628. }
  629. static int ASN1CALL ASN1Dec_ContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfo *val)
  630. {
  631. ASN1decoding_t dd;
  632. ASN1octet_t *di;
  633. ASN1uint32_t t;
  634. ASN1decoding_t dd0;
  635. ASN1octet_t *di0;
  636. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  637. return 0;
  638. ZeroMemory((val)->o, 1);
  639. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  640. return 0;
  641. if (ASN1BERDecPeekTag(dd, &t)) {
  642. if (t == 0x80000000) {
  643. (val)->o[0] |= 0x80;
  644. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  645. return 0;
  646. if (!ASN1BERDecOpenType(dd0, &(val)->content))
  647. return 0;
  648. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  649. return 0;
  650. }
  651. }
  652. if (!ASN1BERDecEndOfContents(dec, dd, di))
  653. return 0;
  654. return 1;
  655. }
  656. static void ASN1CALL ASN1Free_ContentInfo(ContentInfo *val)
  657. {
  658. if (val) {
  659. if ((val)->o[0] & 0x80) {
  660. ASN1open_free(&(val)->content);
  661. }
  662. }
  663. }
  664. static int ASN1CALL ASN1Enc_AuthenticatedSafes(ASN1encoding_t enc, ASN1uint32_t tag, AuthenticatedSafes *val)
  665. {
  666. ASN1uint32_t nLenOff;
  667. ASN1uint32_t i;
  668. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  669. return 0;
  670. for (i = 0; i < (val)->count; i++) {
  671. if (!ASN1Enc_ContentInfo(enc, 0, &((val)->value)[i]))
  672. return 0;
  673. }
  674. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  675. return 0;
  676. return 1;
  677. }
  678. static int ASN1CALL ASN1Dec_AuthenticatedSafes(ASN1decoding_t dec, ASN1uint32_t tag, AuthenticatedSafes *val)
  679. {
  680. ASN1decoding_t dd;
  681. ASN1octet_t *di;
  682. ASN1uint32_t t;
  683. ASN1uint32_t n;
  684. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  685. return 0;
  686. (val)->count = n = 0;
  687. (val)->value = NULL;
  688. while (ASN1BERDecNotEndOfContents(dd, di)) {
  689. if (!ASN1BERDecPeekTag(dd, &t))
  690. return 0;
  691. if ((val)->count >= n) {
  692. n = n ? (n << 1) : 16;
  693. if (!((val)->value = (ContentInfo *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  694. return 0;
  695. }
  696. if (!ASN1Dec_ContentInfo(dd, 0, &((val)->value)[(val)->count]))
  697. return 0;
  698. ((val)->count)++;
  699. }
  700. if (!ASN1BERDecEndOfContents(dec, dd, di))
  701. return 0;
  702. return 1;
  703. }
  704. static void ASN1CALL ASN1Free_AuthenticatedSafes(AuthenticatedSafes *val)
  705. {
  706. ASN1uint32_t i;
  707. if (val) {
  708. ASN1Free_ContentInfo(&(val)->value[0]);
  709. for (i = 1; i < (val)->count; i++) {
  710. ASN1Free_ContentInfo(&(val)->value[i]);
  711. }
  712. ASN1Free((val)->value);
  713. }
  714. }
  715. static int ASN1CALL ASN1Enc_SafeContents(ASN1encoding_t enc, ASN1uint32_t tag, SafeContents *val)
  716. {
  717. ASN1uint32_t nLenOff;
  718. ASN1uint32_t i;
  719. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  720. return 0;
  721. for (i = 0; i < (val)->count; i++) {
  722. if (!ASN1Enc_SafeBag(enc, 0, &((val)->value)[i]))
  723. return 0;
  724. }
  725. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  726. return 0;
  727. return 1;
  728. }
  729. static int ASN1CALL ASN1Dec_SafeContents(ASN1decoding_t dec, ASN1uint32_t tag, SafeContents *val)
  730. {
  731. ASN1decoding_t dd;
  732. ASN1octet_t *di;
  733. ASN1uint32_t t;
  734. ASN1uint32_t n;
  735. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  736. return 0;
  737. (val)->count = n = 0;
  738. (val)->value = NULL;
  739. while (ASN1BERDecNotEndOfContents(dd, di)) {
  740. if (!ASN1BERDecPeekTag(dd, &t))
  741. return 0;
  742. if ((val)->count >= n) {
  743. n = n ? (n << 1) : 16;
  744. if (!((val)->value = (SafeBag *)ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  745. return 0;
  746. }
  747. if (!ASN1Dec_SafeBag(dd, 0, &((val)->value)[(val)->count]))
  748. return 0;
  749. ((val)->count)++;
  750. }
  751. if (!ASN1BERDecEndOfContents(dec, dd, di))
  752. return 0;
  753. return 1;
  754. }
  755. static void ASN1CALL ASN1Free_SafeContents(SafeContents *val)
  756. {
  757. ASN1uint32_t i;
  758. if (val) {
  759. ASN1Free_SafeBag(&(val)->value[0]);
  760. for (i = 1; i < (val)->count; i++) {
  761. ASN1Free_SafeBag(&(val)->value[i]);
  762. }
  763. ASN1Free((val)->value);
  764. }
  765. }
  766. static int ASN1CALL ASN1Enc_SafeBag(ASN1encoding_t enc, ASN1uint32_t tag, SafeBag *val)
  767. {
  768. ASN1uint32_t nLenOff;
  769. ASN1uint32_t nLenOff0;
  770. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  771. return 0;
  772. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->safeBagType))
  773. return 0;
  774. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  775. return 0;
  776. if (!ASN1BEREncOpenType(enc, &(val)->safeBagContent))
  777. return 0;
  778. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  779. return 0;
  780. if ((val)->o[0] & 0x80) {
  781. if (!ASN1Enc_Attributes(enc, 0, &(val)->safeBagAttribs))
  782. return 0;
  783. }
  784. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  785. return 0;
  786. return 1;
  787. }
  788. static int ASN1CALL ASN1Dec_SafeBag(ASN1decoding_t dec, ASN1uint32_t tag, SafeBag *val)
  789. {
  790. ASN1decoding_t dd;
  791. ASN1octet_t *di;
  792. ASN1decoding_t dd0;
  793. ASN1octet_t *di0;
  794. ASN1uint32_t t;
  795. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  796. return 0;
  797. ZeroMemory((val)->o, 1);
  798. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->safeBagType))
  799. return 0;
  800. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  801. return 0;
  802. if (!ASN1BERDecOpenType(dd0, &(val)->safeBagContent))
  803. return 0;
  804. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  805. return 0;
  806. ASN1BERDecPeekTag(dd, &t);
  807. if (t == 0x11) {
  808. (val)->o[0] |= 0x80;
  809. if (!ASN1Dec_Attributes(dd, 0, &(val)->safeBagAttribs))
  810. return 0;
  811. }
  812. if (!ASN1BERDecEndOfContents(dec, dd, di))
  813. return 0;
  814. return 1;
  815. }
  816. static void ASN1CALL ASN1Free_SafeBag(SafeBag *val)
  817. {
  818. if (val) {
  819. ASN1open_free(&(val)->safeBagContent);
  820. if ((val)->o[0] & 0x80) {
  821. ASN1Free_Attributes(&(val)->safeBagAttribs);
  822. }
  823. }
  824. }
  825. static int ASN1CALL ASN1Enc_CertBag(ASN1encoding_t enc, ASN1uint32_t tag, CertBag *val)
  826. {
  827. ASN1uint32_t nLenOff;
  828. ASN1uint32_t nLenOff0;
  829. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  830. return 0;
  831. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->certType))
  832. return 0;
  833. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  834. return 0;
  835. if (!ASN1BEREncOpenType(enc, &(val)->value))
  836. return 0;
  837. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  838. return 0;
  839. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  840. return 0;
  841. return 1;
  842. }
  843. static int ASN1CALL ASN1Dec_CertBag(ASN1decoding_t dec, ASN1uint32_t tag, CertBag *val)
  844. {
  845. ASN1decoding_t dd;
  846. ASN1octet_t *di;
  847. ASN1decoding_t dd0;
  848. ASN1octet_t *di0;
  849. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  850. return 0;
  851. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->certType))
  852. return 0;
  853. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  854. return 0;
  855. if (!ASN1BERDecOpenType(dd0, &(val)->value))
  856. return 0;
  857. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  858. return 0;
  859. if (!ASN1BERDecEndOfContents(dec, dd, di))
  860. return 0;
  861. return 1;
  862. }
  863. static void ASN1CALL ASN1Free_CertBag(CertBag *val)
  864. {
  865. if (val) {
  866. ASN1open_free(&(val)->value);
  867. }
  868. }
  869. static int ASN1CALL ASN1Enc_CRLBag(ASN1encoding_t enc, ASN1uint32_t tag, CRLBag *val)
  870. {
  871. ASN1uint32_t nLenOff;
  872. ASN1uint32_t nLenOff0;
  873. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  874. return 0;
  875. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->crlType))
  876. return 0;
  877. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  878. return 0;
  879. if (!ASN1BEREncOpenType(enc, &(val)->value))
  880. return 0;
  881. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  882. return 0;
  883. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  884. return 0;
  885. return 1;
  886. }
  887. static int ASN1CALL ASN1Dec_CRLBag(ASN1decoding_t dec, ASN1uint32_t tag, CRLBag *val)
  888. {
  889. ASN1decoding_t dd;
  890. ASN1octet_t *di;
  891. ASN1decoding_t dd0;
  892. ASN1octet_t *di0;
  893. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  894. return 0;
  895. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->crlType))
  896. return 0;
  897. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  898. return 0;
  899. if (!ASN1BERDecOpenType(dd0, &(val)->value))
  900. return 0;
  901. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  902. return 0;
  903. if (!ASN1BERDecEndOfContents(dec, dd, di))
  904. return 0;
  905. return 1;
  906. }
  907. static void ASN1CALL ASN1Free_CRLBag(CRLBag *val)
  908. {
  909. if (val) {
  910. ASN1open_free(&(val)->value);
  911. }
  912. }
  913. static int ASN1CALL ASN1Enc_SecretBag(ASN1encoding_t enc, ASN1uint32_t tag, SecretBag *val)
  914. {
  915. ASN1uint32_t nLenOff;
  916. ASN1uint32_t nLenOff0;
  917. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  918. return 0;
  919. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->secretType))
  920. return 0;
  921. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  922. return 0;
  923. if (!ASN1BEREncOpenType(enc, &(val)->secretContent))
  924. return 0;
  925. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  926. return 0;
  927. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  928. return 0;
  929. return 1;
  930. }
  931. static int ASN1CALL ASN1Dec_SecretBag(ASN1decoding_t dec, ASN1uint32_t tag, SecretBag *val)
  932. {
  933. ASN1decoding_t dd;
  934. ASN1octet_t *di;
  935. ASN1decoding_t dd0;
  936. ASN1octet_t *di0;
  937. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  938. return 0;
  939. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->secretType))
  940. return 0;
  941. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  942. return 0;
  943. if (!ASN1BERDecOpenType(dd0, &(val)->secretContent))
  944. return 0;
  945. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  946. return 0;
  947. if (!ASN1BERDecEndOfContents(dec, dd, di))
  948. return 0;
  949. return 1;
  950. }
  951. static void ASN1CALL ASN1Free_SecretBag(SecretBag *val)
  952. {
  953. if (val) {
  954. ASN1open_free(&(val)->secretContent);
  955. }
  956. }
  957. static int ASN1CALL ASN1Enc_PrivateKeyAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  958. {
  959. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  960. return 0;
  961. return 1;
  962. }
  963. static int ASN1CALL ASN1Dec_PrivateKeyAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  964. {
  965. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  966. return 0;
  967. return 1;
  968. }
  969. static void ASN1CALL ASN1Free_PrivateKeyAlgorithmIdentifier(PrivateKeyAlgorithmIdentifier *val)
  970. {
  971. if (val) {
  972. ASN1Free_AlgorithmIdentifier(val);
  973. }
  974. }
  975. static int ASN1CALL ASN1Enc_EncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  976. {
  977. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  978. return 0;
  979. return 1;
  980. }
  981. static int ASN1CALL ASN1Dec_EncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  982. {
  983. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  984. return 0;
  985. return 1;
  986. }
  987. static void ASN1CALL ASN1Free_EncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier *val)
  988. {
  989. if (val) {
  990. ASN1Free_AlgorithmIdentifier(val);
  991. }
  992. }
  993. static int ASN1CALL ASN1Enc_ContentEncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val)
  994. {
  995. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  996. return 0;
  997. return 1;
  998. }
  999. static int ASN1CALL ASN1Dec_ContentEncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val)
  1000. {
  1001. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  1002. return 0;
  1003. return 1;
  1004. }
  1005. static void ASN1CALL ASN1Free_ContentEncryptionAlgorithmIdentifier(ContentEncryptionAlgorithmIdentifier *val)
  1006. {
  1007. if (val) {
  1008. ASN1Free_AlgorithmIdentifier(val);
  1009. }
  1010. }
  1011. static int ASN1CALL ASN1Enc_DigestInfo(ASN1encoding_t enc, ASN1uint32_t tag, DigestInfo *val)
  1012. {
  1013. ASN1uint32_t nLenOff;
  1014. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1015. return 0;
  1016. if (!ASN1Enc_DigestAlgorithmIdentifier(enc, 0, &(val)->digestAlgorithm))
  1017. return 0;
  1018. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->digest).length, ((val)->digest).value))
  1019. return 0;
  1020. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1021. return 0;
  1022. return 1;
  1023. }
  1024. static int ASN1CALL ASN1Dec_DigestInfo(ASN1decoding_t dec, ASN1uint32_t tag, DigestInfo *val)
  1025. {
  1026. ASN1decoding_t dd;
  1027. ASN1octet_t *di;
  1028. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1029. return 0;
  1030. if (!ASN1Dec_DigestAlgorithmIdentifier(dd, 0, &(val)->digestAlgorithm))
  1031. return 0;
  1032. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->digest))
  1033. return 0;
  1034. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1035. return 0;
  1036. return 1;
  1037. }
  1038. static void ASN1CALL ASN1Free_DigestInfo(DigestInfo *val)
  1039. {
  1040. if (val) {
  1041. ASN1Free_DigestAlgorithmIdentifier(&(val)->digestAlgorithm);
  1042. ASN1octetstring_free(&(val)->digest);
  1043. }
  1044. }
  1045. static int ASN1CALL ASN1Enc_MacData(ASN1encoding_t enc, ASN1uint32_t tag, MacData *val)
  1046. {
  1047. ASN1uint32_t nLenOff;
  1048. ASN1octet_t o[1];
  1049. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1050. return 0;
  1051. CopyMemory(o, (val)->o, 1);
  1052. if ((val)->macIterationCount == 1)
  1053. o[0] &= ~0x80;
  1054. if (!ASN1Enc_DigestInfo(enc, 0, &(val)->safeMac))
  1055. return 0;
  1056. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->macSalt).length, ((val)->macSalt).value))
  1057. return 0;
  1058. if (o[0] & 0x80) {
  1059. if (!ASN1BEREncS32(enc, 0x2, (val)->macIterationCount))
  1060. return 0;
  1061. }
  1062. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1063. return 0;
  1064. return 1;
  1065. }
  1066. static int ASN1CALL ASN1Dec_MacData(ASN1decoding_t dec, ASN1uint32_t tag, MacData *val)
  1067. {
  1068. ASN1decoding_t dd;
  1069. ASN1octet_t *di;
  1070. ASN1uint32_t t;
  1071. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1072. return 0;
  1073. ZeroMemory((val)->o, 1);
  1074. if (!ASN1Dec_DigestInfo(dd, 0, &(val)->safeMac))
  1075. return 0;
  1076. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->macSalt))
  1077. return 0;
  1078. ASN1BERDecPeekTag(dd, &t);
  1079. if (t == 0x2) {
  1080. (val)->o[0] |= 0x80;
  1081. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->macIterationCount))
  1082. return 0;
  1083. }
  1084. if (!((val)->o[0] & 0x80))
  1085. (val)->macIterationCount = 1;
  1086. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1087. return 0;
  1088. return 1;
  1089. }
  1090. static void ASN1CALL ASN1Free_MacData(MacData *val)
  1091. {
  1092. if (val) {
  1093. ASN1Free_DigestInfo(&(val)->safeMac);
  1094. ASN1octetstring_free(&(val)->macSalt);
  1095. }
  1096. }
  1097. static int ASN1CALL ASN1Enc_PrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyInfo *val)
  1098. {
  1099. ASN1uint32_t nLenOff;
  1100. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1101. return 0;
  1102. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1103. return 0;
  1104. if (!ASN1Enc_PrivateKeyAlgorithmIdentifier(enc, 0, &(val)->privateKeyAlgorithm))
  1105. return 0;
  1106. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->privateKey).length, ((val)->privateKey).value))
  1107. return 0;
  1108. if ((val)->o[0] & 0x80) {
  1109. if (!ASN1Enc_Attributes(enc, 0x80000000, &(val)->attributes))
  1110. return 0;
  1111. }
  1112. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1113. return 0;
  1114. return 1;
  1115. }
  1116. static int ASN1CALL ASN1Dec_PrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyInfo *val)
  1117. {
  1118. ASN1decoding_t dd;
  1119. ASN1octet_t *di;
  1120. ASN1uint32_t t;
  1121. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1122. return 0;
  1123. ZeroMemory((val)->o, 1);
  1124. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1125. return 0;
  1126. if (!ASN1Dec_PrivateKeyAlgorithmIdentifier(dd, 0, &(val)->privateKeyAlgorithm))
  1127. return 0;
  1128. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->privateKey))
  1129. return 0;
  1130. ASN1BERDecPeekTag(dd, &t);
  1131. if (t == 0x80000000) {
  1132. (val)->o[0] |= 0x80;
  1133. if (!ASN1Dec_Attributes(dd, 0x80000000, &(val)->attributes))
  1134. return 0;
  1135. }
  1136. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1137. return 0;
  1138. return 1;
  1139. }
  1140. static void ASN1CALL ASN1Free_PrivateKeyInfo(PrivateKeyInfo *val)
  1141. {
  1142. if (val) {
  1143. ASN1Free_PrivateKeyAlgorithmIdentifier(&(val)->privateKeyAlgorithm);
  1144. ASN1octetstring_free(&(val)->privateKey);
  1145. if ((val)->o[0] & 0x80) {
  1146. ASN1Free_Attributes(&(val)->attributes);
  1147. }
  1148. }
  1149. }
  1150. static int ASN1CALL ASN1Enc_EncryptedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedContentInfo *val)
  1151. {
  1152. ASN1uint32_t nLenOff;
  1153. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1154. return 0;
  1155. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  1156. return 0;
  1157. if (!ASN1Enc_ContentEncryptionAlgorithmIdentifier(enc, 0, &(val)->contentEncryptionAlg))
  1158. return 0;
  1159. if ((val)->o[0] & 0x80) {
  1160. if (!ASN1DEREncOctetString(enc, 0x80000000, ((val)->encryptedContent).length, ((val)->encryptedContent).value))
  1161. return 0;
  1162. }
  1163. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1164. return 0;
  1165. return 1;
  1166. }
  1167. static int ASN1CALL ASN1Dec_EncryptedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedContentInfo *val)
  1168. {
  1169. ASN1decoding_t dd;
  1170. ASN1octet_t *di;
  1171. ASN1uint32_t t;
  1172. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1173. return 0;
  1174. ZeroMemory((val)->o, 1);
  1175. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  1176. return 0;
  1177. if (!ASN1Dec_ContentEncryptionAlgorithmIdentifier(dd, 0, &(val)->contentEncryptionAlg))
  1178. return 0;
  1179. ASN1BERDecPeekTag(dd, &t);
  1180. if (t == 0x80000000) {
  1181. (val)->o[0] |= 0x80;
  1182. if (!ASN1BERDecOctetString(dd, 0x80000000, &(val)->encryptedContent))
  1183. return 0;
  1184. }
  1185. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1186. return 0;
  1187. return 1;
  1188. }
  1189. static void ASN1CALL ASN1Free_EncryptedContentInfo(EncryptedContentInfo *val)
  1190. {
  1191. if (val) {
  1192. ASN1Free_ContentEncryptionAlgorithmIdentifier(&(val)->contentEncryptionAlg);
  1193. if ((val)->o[0] & 0x80) {
  1194. ASN1octetstring_free(&(val)->encryptedContent);
  1195. }
  1196. }
  1197. }
  1198. static int ASN1CALL ASN1Enc_PFX(ASN1encoding_t enc, ASN1uint32_t tag, PFX *val)
  1199. {
  1200. ASN1uint32_t nLenOff;
  1201. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1202. return 0;
  1203. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1204. return 0;
  1205. if (!ASN1Enc_ContentInfo(enc, 0, &(val)->authSafes))
  1206. return 0;
  1207. if ((val)->o[0] & 0x80) {
  1208. if (!ASN1Enc_MacData(enc, 0, &(val)->macData))
  1209. return 0;
  1210. }
  1211. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1212. return 0;
  1213. return 1;
  1214. }
  1215. static int ASN1CALL ASN1Dec_PFX(ASN1decoding_t dec, ASN1uint32_t tag, PFX *val)
  1216. {
  1217. ASN1decoding_t dd;
  1218. ASN1octet_t *di;
  1219. ASN1uint32_t t;
  1220. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1221. return 0;
  1222. ZeroMemory((val)->o, 1);
  1223. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1224. return 0;
  1225. if (!ASN1Dec_ContentInfo(dd, 0, &(val)->authSafes))
  1226. return 0;
  1227. ASN1BERDecPeekTag(dd, &t);
  1228. if (t == 0x10) {
  1229. (val)->o[0] |= 0x80;
  1230. if (!ASN1Dec_MacData(dd, 0, &(val)->macData))
  1231. return 0;
  1232. }
  1233. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1234. return 0;
  1235. return 1;
  1236. }
  1237. static void ASN1CALL ASN1Free_PFX(PFX *val)
  1238. {
  1239. if (val) {
  1240. ASN1Free_ContentInfo(&(val)->authSafes);
  1241. if ((val)->o[0] & 0x80) {
  1242. ASN1Free_MacData(&(val)->macData);
  1243. }
  1244. }
  1245. }
  1246. static int ASN1CALL ASN1Enc_KeyBag(ASN1encoding_t enc, ASN1uint32_t tag, KeyBag *val)
  1247. {
  1248. if (!ASN1Enc_PrivateKeyInfo(enc, tag, val))
  1249. return 0;
  1250. return 1;
  1251. }
  1252. static int ASN1CALL ASN1Dec_KeyBag(ASN1decoding_t dec, ASN1uint32_t tag, KeyBag *val)
  1253. {
  1254. if (!ASN1Dec_PrivateKeyInfo(dec, tag, val))
  1255. return 0;
  1256. return 1;
  1257. }
  1258. static void ASN1CALL ASN1Free_KeyBag(KeyBag *val)
  1259. {
  1260. if (val) {
  1261. ASN1Free_PrivateKeyInfo(val);
  1262. }
  1263. }
  1264. static int ASN1CALL ASN1Enc_EncryptedData(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedData *val)
  1265. {
  1266. ASN1uint32_t nLenOff;
  1267. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1268. return 0;
  1269. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1270. return 0;
  1271. if (!ASN1Enc_EncryptedContentInfo(enc, 0, &(val)->encryptedContentInfo))
  1272. return 0;
  1273. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1274. return 0;
  1275. return 1;
  1276. }
  1277. static int ASN1CALL ASN1Dec_EncryptedData(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedData *val)
  1278. {
  1279. ASN1decoding_t dd;
  1280. ASN1octet_t *di;
  1281. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1282. return 0;
  1283. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1284. return 0;
  1285. if (!ASN1Dec_EncryptedContentInfo(dd, 0, &(val)->encryptedContentInfo))
  1286. return 0;
  1287. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1288. return 0;
  1289. return 1;
  1290. }
  1291. static void ASN1CALL ASN1Free_EncryptedData(EncryptedData *val)
  1292. {
  1293. if (val) {
  1294. ASN1Free_EncryptedContentInfo(&(val)->encryptedContentInfo);
  1295. }
  1296. }
  1297. static int ASN1CALL ASN1Enc_EncryptedPrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  1298. {
  1299. ASN1uint32_t nLenOff;
  1300. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1301. return 0;
  1302. if (!ASN1Enc_EncryptionAlgorithmIdentifier(enc, 0, &(val)->encryptionAlgorithm))
  1303. return 0;
  1304. if (!ASN1Enc_EncryptedData(enc, 0, &(val)->encryptedData))
  1305. return 0;
  1306. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1307. return 0;
  1308. return 1;
  1309. }
  1310. static int ASN1CALL ASN1Dec_EncryptedPrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  1311. {
  1312. ASN1decoding_t dd;
  1313. ASN1octet_t *di;
  1314. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1315. return 0;
  1316. if (!ASN1Dec_EncryptionAlgorithmIdentifier(dd, 0, &(val)->encryptionAlgorithm))
  1317. return 0;
  1318. if (!ASN1Dec_EncryptedData(dd, 0, &(val)->encryptedData))
  1319. return 0;
  1320. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1321. return 0;
  1322. return 1;
  1323. }
  1324. static void ASN1CALL ASN1Free_EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo *val)
  1325. {
  1326. if (val) {
  1327. ASN1Free_EncryptionAlgorithmIdentifier(&(val)->encryptionAlgorithm);
  1328. ASN1Free_EncryptedData(&(val)->encryptedData);
  1329. }
  1330. }
  1331. static int ASN1CALL ASN1Enc_Pkcs_8ShroudedKeyBag(ASN1encoding_t enc, ASN1uint32_t tag, Pkcs_8ShroudedKeyBag *val)
  1332. {
  1333. if (!ASN1Enc_EncryptedPrivateKeyInfo(enc, tag, val))
  1334. return 0;
  1335. return 1;
  1336. }
  1337. static int ASN1CALL ASN1Dec_Pkcs_8ShroudedKeyBag(ASN1decoding_t dec, ASN1uint32_t tag, Pkcs_8ShroudedKeyBag *val)
  1338. {
  1339. if (!ASN1Dec_EncryptedPrivateKeyInfo(dec, tag, val))
  1340. return 0;
  1341. return 1;
  1342. }
  1343. static void ASN1CALL ASN1Free_Pkcs_8ShroudedKeyBag(Pkcs_8ShroudedKeyBag *val)
  1344. {
  1345. if (val) {
  1346. ASN1Free_EncryptedPrivateKeyInfo(val);
  1347. }
  1348. }