Leaked source code of windows server 2003
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.

1454 lines
47 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. void *pvASN1DecRealloc;
  493. n = n ? (n << 1) : 16;
  494. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  495. return 0;
  496. (val)->value = (AttributeSetValue_Set *) pvASN1DecRealloc;
  497. }
  498. if (!ASN1BERDecOpenType(dd, &((val)->value)[(val)->count]))
  499. return 0;
  500. ((val)->count)++;
  501. }
  502. if (!ASN1BERDecEndOfContents(dec, dd, di))
  503. return 0;
  504. return 1;
  505. }
  506. static void ASN1CALL ASN1Free_AttributeSetValue(AttributeSetValue *val)
  507. {
  508. ASN1uint32_t i;
  509. if (val) {
  510. ASN1open_free(&(val)->value[0]);
  511. for (i = 1; i < (val)->count; i++) {
  512. ASN1open_free(&(val)->value[i]);
  513. }
  514. ASN1Free((val)->value);
  515. }
  516. }
  517. static int ASN1CALL ASN1Enc_Attribute(ASN1encoding_t enc, ASN1uint32_t tag, Attribute *val)
  518. {
  519. ASN1uint32_t nLenOff;
  520. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  521. return 0;
  522. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->attributeType))
  523. return 0;
  524. if (!ASN1Enc_AttributeSetValue(enc, 0, &(val)->attributeValue))
  525. return 0;
  526. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  527. return 0;
  528. return 1;
  529. }
  530. static int ASN1CALL ASN1Dec_Attribute(ASN1decoding_t dec, ASN1uint32_t tag, Attribute *val)
  531. {
  532. ASN1decoding_t dd;
  533. ASN1octet_t *di;
  534. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  535. return 0;
  536. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->attributeType))
  537. return 0;
  538. if (!ASN1Dec_AttributeSetValue(dd, 0, &(val)->attributeValue))
  539. return 0;
  540. if (!ASN1BERDecEndOfContents(dec, dd, di))
  541. return 0;
  542. return 1;
  543. }
  544. static void ASN1CALL ASN1Free_Attribute(Attribute *val)
  545. {
  546. if (val) {
  547. ASN1Free_AttributeSetValue(&(val)->attributeValue);
  548. }
  549. }
  550. static int ASN1CALL ASN1Enc_Attributes(ASN1encoding_t enc, ASN1uint32_t tag, Attributes *val)
  551. {
  552. ASN1uint32_t nLenOff;
  553. void *pBlk;
  554. ASN1uint32_t i;
  555. ASN1encoding_t enc2;
  556. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x11, &nLenOff))
  557. return 0;
  558. if (!ASN1DEREncBeginBlk(enc, ASN1_DER_SET_OF_BLOCK, &pBlk))
  559. return 0;
  560. for (i = 0; i < (val)->count; i++) {
  561. if (!ASN1DEREncNewBlkElement(pBlk, &enc2))
  562. return 0;
  563. if (!ASN1Enc_Attribute(enc2, 0, &((val)->value)[i]))
  564. return 0;
  565. if (!ASN1DEREncFlushBlkElement(pBlk))
  566. return 0;
  567. }
  568. if (!ASN1DEREncEndBlk(pBlk))
  569. return 0;
  570. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  571. return 0;
  572. return 1;
  573. }
  574. static int ASN1CALL ASN1Dec_Attributes(ASN1decoding_t dec, ASN1uint32_t tag, Attributes *val)
  575. {
  576. ASN1decoding_t dd;
  577. ASN1octet_t *di;
  578. ASN1uint32_t t;
  579. ASN1uint32_t n;
  580. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x11, &dd, &di))
  581. return 0;
  582. (val)->count = n = 0;
  583. (val)->value = NULL;
  584. while (ASN1BERDecNotEndOfContents(dd, di)) {
  585. if (!ASN1BERDecPeekTag(dd, &t))
  586. return 0;
  587. if ((val)->count >= n) {
  588. void *pvASN1DecRealloc;
  589. n = n ? (n << 1) : 16;
  590. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  591. return 0;
  592. (val)->value = (Attribute *) pvASN1DecRealloc;
  593. }
  594. if (!ASN1Dec_Attribute(dd, 0, &((val)->value)[(val)->count]))
  595. return 0;
  596. ((val)->count)++;
  597. }
  598. if (!ASN1BERDecEndOfContents(dec, dd, di))
  599. return 0;
  600. return 1;
  601. }
  602. static void ASN1CALL ASN1Free_Attributes(Attributes *val)
  603. {
  604. ASN1uint32_t i;
  605. if (val) {
  606. ASN1Free_Attribute(&(val)->value[0]);
  607. for (i = 1; i < (val)->count; i++) {
  608. ASN1Free_Attribute(&(val)->value[i]);
  609. }
  610. ASN1Free((val)->value);
  611. }
  612. }
  613. static int ASN1CALL ASN1Enc_ContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, ContentInfo *val)
  614. {
  615. ASN1uint32_t nLenOff;
  616. ASN1uint32_t nLenOff0;
  617. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  618. return 0;
  619. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  620. return 0;
  621. if ((val)->o[0] & 0x80) {
  622. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  623. return 0;
  624. if (!ASN1BEREncOpenType(enc, &(val)->content))
  625. return 0;
  626. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  627. return 0;
  628. }
  629. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  630. return 0;
  631. return 1;
  632. }
  633. static int ASN1CALL ASN1Dec_ContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, ContentInfo *val)
  634. {
  635. ASN1decoding_t dd;
  636. ASN1octet_t *di;
  637. ASN1uint32_t t;
  638. ASN1decoding_t dd0;
  639. ASN1octet_t *di0;
  640. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  641. return 0;
  642. ZeroMemory((val)->o, 1);
  643. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  644. return 0;
  645. if (ASN1BERDecPeekTag(dd, &t)) {
  646. if (t == 0x80000000) {
  647. (val)->o[0] |= 0x80;
  648. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  649. return 0;
  650. if (!ASN1BERDecOpenType(dd0, &(val)->content))
  651. return 0;
  652. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  653. return 0;
  654. }
  655. }
  656. if (!ASN1BERDecEndOfContents(dec, dd, di))
  657. return 0;
  658. return 1;
  659. }
  660. static void ASN1CALL ASN1Free_ContentInfo(ContentInfo *val)
  661. {
  662. if (val) {
  663. if ((val)->o[0] & 0x80) {
  664. ASN1open_free(&(val)->content);
  665. }
  666. }
  667. }
  668. static int ASN1CALL ASN1Enc_AuthenticatedSafes(ASN1encoding_t enc, ASN1uint32_t tag, AuthenticatedSafes *val)
  669. {
  670. ASN1uint32_t nLenOff;
  671. ASN1uint32_t i;
  672. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  673. return 0;
  674. for (i = 0; i < (val)->count; i++) {
  675. if (!ASN1Enc_ContentInfo(enc, 0, &((val)->value)[i]))
  676. return 0;
  677. }
  678. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  679. return 0;
  680. return 1;
  681. }
  682. static int ASN1CALL ASN1Dec_AuthenticatedSafes(ASN1decoding_t dec, ASN1uint32_t tag, AuthenticatedSafes *val)
  683. {
  684. ASN1decoding_t dd;
  685. ASN1octet_t *di;
  686. ASN1uint32_t t;
  687. ASN1uint32_t n;
  688. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  689. return 0;
  690. (val)->count = n = 0;
  691. (val)->value = NULL;
  692. while (ASN1BERDecNotEndOfContents(dd, di)) {
  693. if (!ASN1BERDecPeekTag(dd, &t))
  694. return 0;
  695. if ((val)->count >= n) {
  696. void *pvASN1DecRealloc;
  697. n = n ? (n << 1) : 16;
  698. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  699. return 0;
  700. (val)->value = (ContentInfo *) pvASN1DecRealloc;
  701. }
  702. if (!ASN1Dec_ContentInfo(dd, 0, &((val)->value)[(val)->count]))
  703. return 0;
  704. ((val)->count)++;
  705. }
  706. if (!ASN1BERDecEndOfContents(dec, dd, di))
  707. return 0;
  708. return 1;
  709. }
  710. static void ASN1CALL ASN1Free_AuthenticatedSafes(AuthenticatedSafes *val)
  711. {
  712. ASN1uint32_t i;
  713. if (val) {
  714. ASN1Free_ContentInfo(&(val)->value[0]);
  715. for (i = 1; i < (val)->count; i++) {
  716. ASN1Free_ContentInfo(&(val)->value[i]);
  717. }
  718. ASN1Free((val)->value);
  719. }
  720. }
  721. static int ASN1CALL ASN1Enc_SafeContents(ASN1encoding_t enc, ASN1uint32_t tag, SafeContents *val)
  722. {
  723. ASN1uint32_t nLenOff;
  724. ASN1uint32_t i;
  725. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  726. return 0;
  727. for (i = 0; i < (val)->count; i++) {
  728. if (!ASN1Enc_SafeBag(enc, 0, &((val)->value)[i]))
  729. return 0;
  730. }
  731. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  732. return 0;
  733. return 1;
  734. }
  735. static int ASN1CALL ASN1Dec_SafeContents(ASN1decoding_t dec, ASN1uint32_t tag, SafeContents *val)
  736. {
  737. ASN1decoding_t dd;
  738. ASN1octet_t *di;
  739. ASN1uint32_t t;
  740. ASN1uint32_t n;
  741. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  742. return 0;
  743. (val)->count = n = 0;
  744. (val)->value = NULL;
  745. while (ASN1BERDecNotEndOfContents(dd, di)) {
  746. if (!ASN1BERDecPeekTag(dd, &t))
  747. return 0;
  748. if ((val)->count >= n) {
  749. void *pvASN1DecRealloc;
  750. n = n ? (n << 1) : 16;
  751. if (!(pvASN1DecRealloc = ASN1DecRealloc(dd, (val)->value, n * sizeof(*(val)->value))))
  752. return 0;
  753. (val)->value = (SafeBag *) pvASN1DecRealloc;
  754. }
  755. if (!ASN1Dec_SafeBag(dd, 0, &((val)->value)[(val)->count]))
  756. return 0;
  757. ((val)->count)++;
  758. }
  759. if (!ASN1BERDecEndOfContents(dec, dd, di))
  760. return 0;
  761. return 1;
  762. }
  763. static void ASN1CALL ASN1Free_SafeContents(SafeContents *val)
  764. {
  765. ASN1uint32_t i;
  766. if (val) {
  767. ASN1Free_SafeBag(&(val)->value[0]);
  768. for (i = 1; i < (val)->count; i++) {
  769. ASN1Free_SafeBag(&(val)->value[i]);
  770. }
  771. ASN1Free((val)->value);
  772. }
  773. }
  774. static int ASN1CALL ASN1Enc_SafeBag(ASN1encoding_t enc, ASN1uint32_t tag, SafeBag *val)
  775. {
  776. ASN1uint32_t nLenOff;
  777. ASN1uint32_t nLenOff0;
  778. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  779. return 0;
  780. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->safeBagType))
  781. return 0;
  782. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  783. return 0;
  784. if (!ASN1BEREncOpenType(enc, &(val)->safeBagContent))
  785. return 0;
  786. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  787. return 0;
  788. if ((val)->o[0] & 0x80) {
  789. if (!ASN1Enc_Attributes(enc, 0, &(val)->safeBagAttribs))
  790. return 0;
  791. }
  792. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  793. return 0;
  794. return 1;
  795. }
  796. static int ASN1CALL ASN1Dec_SafeBag(ASN1decoding_t dec, ASN1uint32_t tag, SafeBag *val)
  797. {
  798. ASN1decoding_t dd;
  799. ASN1octet_t *di;
  800. ASN1decoding_t dd0;
  801. ASN1octet_t *di0;
  802. ASN1uint32_t t;
  803. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  804. return 0;
  805. ZeroMemory((val)->o, 1);
  806. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->safeBagType))
  807. return 0;
  808. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  809. return 0;
  810. if (!ASN1BERDecOpenType(dd0, &(val)->safeBagContent))
  811. return 0;
  812. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  813. return 0;
  814. ASN1BERDecPeekTag(dd, &t);
  815. if (t == 0x11) {
  816. (val)->o[0] |= 0x80;
  817. if (!ASN1Dec_Attributes(dd, 0, &(val)->safeBagAttribs))
  818. return 0;
  819. }
  820. if (!ASN1BERDecEndOfContents(dec, dd, di))
  821. return 0;
  822. return 1;
  823. }
  824. static void ASN1CALL ASN1Free_SafeBag(SafeBag *val)
  825. {
  826. if (val) {
  827. ASN1open_free(&(val)->safeBagContent);
  828. if ((val)->o[0] & 0x80) {
  829. ASN1Free_Attributes(&(val)->safeBagAttribs);
  830. }
  831. }
  832. }
  833. static int ASN1CALL ASN1Enc_CertBag(ASN1encoding_t enc, ASN1uint32_t tag, CertBag *val)
  834. {
  835. ASN1uint32_t nLenOff;
  836. ASN1uint32_t nLenOff0;
  837. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  838. return 0;
  839. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->certType))
  840. return 0;
  841. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  842. return 0;
  843. if (!ASN1BEREncOpenType(enc, &(val)->value))
  844. return 0;
  845. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  846. return 0;
  847. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  848. return 0;
  849. return 1;
  850. }
  851. static int ASN1CALL ASN1Dec_CertBag(ASN1decoding_t dec, ASN1uint32_t tag, CertBag *val)
  852. {
  853. ASN1decoding_t dd;
  854. ASN1octet_t *di;
  855. ASN1decoding_t dd0;
  856. ASN1octet_t *di0;
  857. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  858. return 0;
  859. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->certType))
  860. return 0;
  861. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  862. return 0;
  863. if (!ASN1BERDecOpenType(dd0, &(val)->value))
  864. return 0;
  865. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  866. return 0;
  867. if (!ASN1BERDecEndOfContents(dec, dd, di))
  868. return 0;
  869. return 1;
  870. }
  871. static void ASN1CALL ASN1Free_CertBag(CertBag *val)
  872. {
  873. if (val) {
  874. ASN1open_free(&(val)->value);
  875. }
  876. }
  877. static int ASN1CALL ASN1Enc_CRLBag(ASN1encoding_t enc, ASN1uint32_t tag, CRLBag *val)
  878. {
  879. ASN1uint32_t nLenOff;
  880. ASN1uint32_t nLenOff0;
  881. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  882. return 0;
  883. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->crlType))
  884. return 0;
  885. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  886. return 0;
  887. if (!ASN1BEREncOpenType(enc, &(val)->value))
  888. return 0;
  889. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  890. return 0;
  891. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  892. return 0;
  893. return 1;
  894. }
  895. static int ASN1CALL ASN1Dec_CRLBag(ASN1decoding_t dec, ASN1uint32_t tag, CRLBag *val)
  896. {
  897. ASN1decoding_t dd;
  898. ASN1octet_t *di;
  899. ASN1decoding_t dd0;
  900. ASN1octet_t *di0;
  901. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  902. return 0;
  903. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->crlType))
  904. return 0;
  905. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  906. return 0;
  907. if (!ASN1BERDecOpenType(dd0, &(val)->value))
  908. return 0;
  909. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  910. return 0;
  911. if (!ASN1BERDecEndOfContents(dec, dd, di))
  912. return 0;
  913. return 1;
  914. }
  915. static void ASN1CALL ASN1Free_CRLBag(CRLBag *val)
  916. {
  917. if (val) {
  918. ASN1open_free(&(val)->value);
  919. }
  920. }
  921. static int ASN1CALL ASN1Enc_SecretBag(ASN1encoding_t enc, ASN1uint32_t tag, SecretBag *val)
  922. {
  923. ASN1uint32_t nLenOff;
  924. ASN1uint32_t nLenOff0;
  925. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  926. return 0;
  927. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->secretType))
  928. return 0;
  929. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  930. return 0;
  931. if (!ASN1BEREncOpenType(enc, &(val)->secretContent))
  932. return 0;
  933. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  934. return 0;
  935. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  936. return 0;
  937. return 1;
  938. }
  939. static int ASN1CALL ASN1Dec_SecretBag(ASN1decoding_t dec, ASN1uint32_t tag, SecretBag *val)
  940. {
  941. ASN1decoding_t dd;
  942. ASN1octet_t *di;
  943. ASN1decoding_t dd0;
  944. ASN1octet_t *di0;
  945. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  946. return 0;
  947. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->secretType))
  948. return 0;
  949. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  950. return 0;
  951. if (!ASN1BERDecOpenType(dd0, &(val)->secretContent))
  952. return 0;
  953. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  954. return 0;
  955. if (!ASN1BERDecEndOfContents(dec, dd, di))
  956. return 0;
  957. return 1;
  958. }
  959. static void ASN1CALL ASN1Free_SecretBag(SecretBag *val)
  960. {
  961. if (val) {
  962. ASN1open_free(&(val)->secretContent);
  963. }
  964. }
  965. static int ASN1CALL ASN1Enc_PrivateKeyAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  966. {
  967. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  968. return 0;
  969. return 1;
  970. }
  971. static int ASN1CALL ASN1Dec_PrivateKeyAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyAlgorithmIdentifier *val)
  972. {
  973. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  974. return 0;
  975. return 1;
  976. }
  977. static void ASN1CALL ASN1Free_PrivateKeyAlgorithmIdentifier(PrivateKeyAlgorithmIdentifier *val)
  978. {
  979. if (val) {
  980. ASN1Free_AlgorithmIdentifier(val);
  981. }
  982. }
  983. static int ASN1CALL ASN1Enc_EncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  984. {
  985. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  986. return 0;
  987. return 1;
  988. }
  989. static int ASN1CALL ASN1Dec_EncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, EncryptionAlgorithmIdentifier *val)
  990. {
  991. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  992. return 0;
  993. return 1;
  994. }
  995. static void ASN1CALL ASN1Free_EncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier *val)
  996. {
  997. if (val) {
  998. ASN1Free_AlgorithmIdentifier(val);
  999. }
  1000. }
  1001. static int ASN1CALL ASN1Enc_ContentEncryptionAlgorithmIdentifier(ASN1encoding_t enc, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val)
  1002. {
  1003. if (!ASN1Enc_AlgorithmIdentifier(enc, tag, val))
  1004. return 0;
  1005. return 1;
  1006. }
  1007. static int ASN1CALL ASN1Dec_ContentEncryptionAlgorithmIdentifier(ASN1decoding_t dec, ASN1uint32_t tag, ContentEncryptionAlgorithmIdentifier *val)
  1008. {
  1009. if (!ASN1Dec_AlgorithmIdentifier(dec, tag, val))
  1010. return 0;
  1011. return 1;
  1012. }
  1013. static void ASN1CALL ASN1Free_ContentEncryptionAlgorithmIdentifier(ContentEncryptionAlgorithmIdentifier *val)
  1014. {
  1015. if (val) {
  1016. ASN1Free_AlgorithmIdentifier(val);
  1017. }
  1018. }
  1019. static int ASN1CALL ASN1Enc_DigestInfo(ASN1encoding_t enc, ASN1uint32_t tag, DigestInfo *val)
  1020. {
  1021. ASN1uint32_t nLenOff;
  1022. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1023. return 0;
  1024. if (!ASN1Enc_DigestAlgorithmIdentifier(enc, 0, &(val)->digestAlgorithm))
  1025. return 0;
  1026. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->digest).length, ((val)->digest).value))
  1027. return 0;
  1028. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1029. return 0;
  1030. return 1;
  1031. }
  1032. static int ASN1CALL ASN1Dec_DigestInfo(ASN1decoding_t dec, ASN1uint32_t tag, DigestInfo *val)
  1033. {
  1034. ASN1decoding_t dd;
  1035. ASN1octet_t *di;
  1036. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1037. return 0;
  1038. if (!ASN1Dec_DigestAlgorithmIdentifier(dd, 0, &(val)->digestAlgorithm))
  1039. return 0;
  1040. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->digest))
  1041. return 0;
  1042. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1043. return 0;
  1044. return 1;
  1045. }
  1046. static void ASN1CALL ASN1Free_DigestInfo(DigestInfo *val)
  1047. {
  1048. if (val) {
  1049. ASN1Free_DigestAlgorithmIdentifier(&(val)->digestAlgorithm);
  1050. ASN1octetstring_free(&(val)->digest);
  1051. }
  1052. }
  1053. static int ASN1CALL ASN1Enc_MacData(ASN1encoding_t enc, ASN1uint32_t tag, MacData *val)
  1054. {
  1055. ASN1uint32_t nLenOff;
  1056. ASN1octet_t o[1];
  1057. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1058. return 0;
  1059. CopyMemory(o, (val)->o, 1);
  1060. if ((val)->macIterationCount == 1)
  1061. o[0] &= ~0x80;
  1062. if (!ASN1Enc_DigestInfo(enc, 0, &(val)->safeMac))
  1063. return 0;
  1064. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->macSalt).length, ((val)->macSalt).value))
  1065. return 0;
  1066. if (o[0] & 0x80) {
  1067. if (!ASN1BEREncS32(enc, 0x2, (val)->macIterationCount))
  1068. return 0;
  1069. }
  1070. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1071. return 0;
  1072. return 1;
  1073. }
  1074. static int ASN1CALL ASN1Dec_MacData(ASN1decoding_t dec, ASN1uint32_t tag, MacData *val)
  1075. {
  1076. ASN1decoding_t dd;
  1077. ASN1octet_t *di;
  1078. ASN1uint32_t t;
  1079. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1080. return 0;
  1081. ZeroMemory((val)->o, 1);
  1082. if (!ASN1Dec_DigestInfo(dd, 0, &(val)->safeMac))
  1083. return 0;
  1084. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->macSalt))
  1085. return 0;
  1086. ASN1BERDecPeekTag(dd, &t);
  1087. if (t == 0x2) {
  1088. (val)->o[0] |= 0x80;
  1089. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->macIterationCount))
  1090. return 0;
  1091. }
  1092. if (!((val)->o[0] & 0x80))
  1093. (val)->macIterationCount = 1;
  1094. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1095. return 0;
  1096. return 1;
  1097. }
  1098. static void ASN1CALL ASN1Free_MacData(MacData *val)
  1099. {
  1100. if (val) {
  1101. ASN1Free_DigestInfo(&(val)->safeMac);
  1102. ASN1octetstring_free(&(val)->macSalt);
  1103. }
  1104. }
  1105. static int ASN1CALL ASN1Enc_PrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, PrivateKeyInfo *val)
  1106. {
  1107. ASN1uint32_t nLenOff;
  1108. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1109. return 0;
  1110. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1111. return 0;
  1112. if (!ASN1Enc_PrivateKeyAlgorithmIdentifier(enc, 0, &(val)->privateKeyAlgorithm))
  1113. return 0;
  1114. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->privateKey).length, ((val)->privateKey).value))
  1115. return 0;
  1116. if ((val)->o[0] & 0x80) {
  1117. if (!ASN1Enc_Attributes(enc, 0x80000000, &(val)->attributes))
  1118. return 0;
  1119. }
  1120. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1121. return 0;
  1122. return 1;
  1123. }
  1124. static int ASN1CALL ASN1Dec_PrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, PrivateKeyInfo *val)
  1125. {
  1126. ASN1decoding_t dd;
  1127. ASN1octet_t *di;
  1128. ASN1uint32_t t;
  1129. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1130. return 0;
  1131. ZeroMemory((val)->o, 1);
  1132. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1133. return 0;
  1134. if (!ASN1Dec_PrivateKeyAlgorithmIdentifier(dd, 0, &(val)->privateKeyAlgorithm))
  1135. return 0;
  1136. if (!ASN1BERDecOctetString(dd, 0x4, &(val)->privateKey))
  1137. return 0;
  1138. ASN1BERDecPeekTag(dd, &t);
  1139. if (t == 0x80000000) {
  1140. (val)->o[0] |= 0x80;
  1141. if (!ASN1Dec_Attributes(dd, 0x80000000, &(val)->attributes))
  1142. return 0;
  1143. }
  1144. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1145. return 0;
  1146. return 1;
  1147. }
  1148. static void ASN1CALL ASN1Free_PrivateKeyInfo(PrivateKeyInfo *val)
  1149. {
  1150. if (val) {
  1151. ASN1Free_PrivateKeyAlgorithmIdentifier(&(val)->privateKeyAlgorithm);
  1152. ASN1octetstring_free(&(val)->privateKey);
  1153. if ((val)->o[0] & 0x80) {
  1154. ASN1Free_Attributes(&(val)->attributes);
  1155. }
  1156. }
  1157. }
  1158. static int ASN1CALL ASN1Enc_EncryptedContentInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedContentInfo *val)
  1159. {
  1160. ASN1uint32_t nLenOff;
  1161. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1162. return 0;
  1163. if (!ASN1BEREncObjectIdentifier2(enc, 0x6, &(val)->contentType))
  1164. return 0;
  1165. if (!ASN1Enc_ContentEncryptionAlgorithmIdentifier(enc, 0, &(val)->contentEncryptionAlg))
  1166. return 0;
  1167. if ((val)->o[0] & 0x80) {
  1168. if (!ASN1DEREncOctetString(enc, 0x80000000, ((val)->encryptedContent).length, ((val)->encryptedContent).value))
  1169. return 0;
  1170. }
  1171. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1172. return 0;
  1173. return 1;
  1174. }
  1175. static int ASN1CALL ASN1Dec_EncryptedContentInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedContentInfo *val)
  1176. {
  1177. ASN1decoding_t dd;
  1178. ASN1octet_t *di;
  1179. ASN1uint32_t t;
  1180. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1181. return 0;
  1182. ZeroMemory((val)->o, 1);
  1183. if (!ASN1BERDecObjectIdentifier2(dd, 0x6, &(val)->contentType))
  1184. return 0;
  1185. if (!ASN1Dec_ContentEncryptionAlgorithmIdentifier(dd, 0, &(val)->contentEncryptionAlg))
  1186. return 0;
  1187. ASN1BERDecPeekTag(dd, &t);
  1188. if (t == 0x80000000) {
  1189. (val)->o[0] |= 0x80;
  1190. if (!ASN1BERDecOctetString(dd, 0x80000000, &(val)->encryptedContent))
  1191. return 0;
  1192. }
  1193. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1194. return 0;
  1195. return 1;
  1196. }
  1197. static void ASN1CALL ASN1Free_EncryptedContentInfo(EncryptedContentInfo *val)
  1198. {
  1199. if (val) {
  1200. ASN1Free_ContentEncryptionAlgorithmIdentifier(&(val)->contentEncryptionAlg);
  1201. if ((val)->o[0] & 0x80) {
  1202. ASN1octetstring_free(&(val)->encryptedContent);
  1203. }
  1204. }
  1205. }
  1206. static int ASN1CALL ASN1Enc_PFX(ASN1encoding_t enc, ASN1uint32_t tag, PFX *val)
  1207. {
  1208. ASN1uint32_t nLenOff;
  1209. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1210. return 0;
  1211. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1212. return 0;
  1213. if (!ASN1Enc_ContentInfo(enc, 0, &(val)->authSafes))
  1214. return 0;
  1215. if ((val)->o[0] & 0x80) {
  1216. if (!ASN1Enc_MacData(enc, 0, &(val)->macData))
  1217. return 0;
  1218. }
  1219. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1220. return 0;
  1221. return 1;
  1222. }
  1223. static int ASN1CALL ASN1Dec_PFX(ASN1decoding_t dec, ASN1uint32_t tag, PFX *val)
  1224. {
  1225. ASN1decoding_t dd;
  1226. ASN1octet_t *di;
  1227. ASN1uint32_t t;
  1228. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1229. return 0;
  1230. ZeroMemory((val)->o, 1);
  1231. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1232. return 0;
  1233. if (!ASN1Dec_ContentInfo(dd, 0, &(val)->authSafes))
  1234. return 0;
  1235. ASN1BERDecPeekTag(dd, &t);
  1236. if (t == 0x10) {
  1237. (val)->o[0] |= 0x80;
  1238. if (!ASN1Dec_MacData(dd, 0, &(val)->macData))
  1239. return 0;
  1240. }
  1241. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1242. return 0;
  1243. return 1;
  1244. }
  1245. static void ASN1CALL ASN1Free_PFX(PFX *val)
  1246. {
  1247. if (val) {
  1248. ASN1Free_ContentInfo(&(val)->authSafes);
  1249. if ((val)->o[0] & 0x80) {
  1250. ASN1Free_MacData(&(val)->macData);
  1251. }
  1252. }
  1253. }
  1254. static int ASN1CALL ASN1Enc_KeyBag(ASN1encoding_t enc, ASN1uint32_t tag, KeyBag *val)
  1255. {
  1256. if (!ASN1Enc_PrivateKeyInfo(enc, tag, val))
  1257. return 0;
  1258. return 1;
  1259. }
  1260. static int ASN1CALL ASN1Dec_KeyBag(ASN1decoding_t dec, ASN1uint32_t tag, KeyBag *val)
  1261. {
  1262. if (!ASN1Dec_PrivateKeyInfo(dec, tag, val))
  1263. return 0;
  1264. return 1;
  1265. }
  1266. static void ASN1CALL ASN1Free_KeyBag(KeyBag *val)
  1267. {
  1268. if (val) {
  1269. ASN1Free_PrivateKeyInfo(val);
  1270. }
  1271. }
  1272. static int ASN1CALL ASN1Enc_EncryptedData(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedData *val)
  1273. {
  1274. ASN1uint32_t nLenOff;
  1275. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1276. return 0;
  1277. if (!ASN1BEREncS32(enc, 0x2, (val)->version))
  1278. return 0;
  1279. if (!ASN1Enc_EncryptedContentInfo(enc, 0, &(val)->encryptedContentInfo))
  1280. return 0;
  1281. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1282. return 0;
  1283. return 1;
  1284. }
  1285. static int ASN1CALL ASN1Dec_EncryptedData(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedData *val)
  1286. {
  1287. ASN1decoding_t dd;
  1288. ASN1octet_t *di;
  1289. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1290. return 0;
  1291. if (!ASN1BERDecS32Val(dd, 0x2, &(val)->version))
  1292. return 0;
  1293. if (!ASN1Dec_EncryptedContentInfo(dd, 0, &(val)->encryptedContentInfo))
  1294. return 0;
  1295. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1296. return 0;
  1297. return 1;
  1298. }
  1299. static void ASN1CALL ASN1Free_EncryptedData(EncryptedData *val)
  1300. {
  1301. if (val) {
  1302. ASN1Free_EncryptedContentInfo(&(val)->encryptedContentInfo);
  1303. }
  1304. }
  1305. static int ASN1CALL ASN1Enc_EncryptedPrivateKeyInfo(ASN1encoding_t enc, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  1306. {
  1307. ASN1uint32_t nLenOff;
  1308. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  1309. return 0;
  1310. if (!ASN1Enc_EncryptionAlgorithmIdentifier(enc, 0, &(val)->encryptionAlgorithm))
  1311. return 0;
  1312. if (!ASN1Enc_EncryptedData(enc, 0, &(val)->encryptedData))
  1313. return 0;
  1314. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  1315. return 0;
  1316. return 1;
  1317. }
  1318. static int ASN1CALL ASN1Dec_EncryptedPrivateKeyInfo(ASN1decoding_t dec, ASN1uint32_t tag, EncryptedPrivateKeyInfo *val)
  1319. {
  1320. ASN1decoding_t dd;
  1321. ASN1octet_t *di;
  1322. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  1323. return 0;
  1324. if (!ASN1Dec_EncryptionAlgorithmIdentifier(dd, 0, &(val)->encryptionAlgorithm))
  1325. return 0;
  1326. if (!ASN1Dec_EncryptedData(dd, 0, &(val)->encryptedData))
  1327. return 0;
  1328. if (!ASN1BERDecEndOfContents(dec, dd, di))
  1329. return 0;
  1330. return 1;
  1331. }
  1332. static void ASN1CALL ASN1Free_EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo *val)
  1333. {
  1334. if (val) {
  1335. ASN1Free_EncryptionAlgorithmIdentifier(&(val)->encryptionAlgorithm);
  1336. ASN1Free_EncryptedData(&(val)->encryptedData);
  1337. }
  1338. }
  1339. static int ASN1CALL ASN1Enc_Pkcs_8ShroudedKeyBag(ASN1encoding_t enc, ASN1uint32_t tag, Pkcs_8ShroudedKeyBag *val)
  1340. {
  1341. if (!ASN1Enc_EncryptedPrivateKeyInfo(enc, tag, val))
  1342. return 0;
  1343. return 1;
  1344. }
  1345. static int ASN1CALL ASN1Dec_Pkcs_8ShroudedKeyBag(ASN1decoding_t dec, ASN1uint32_t tag, Pkcs_8ShroudedKeyBag *val)
  1346. {
  1347. if (!ASN1Dec_EncryptedPrivateKeyInfo(dec, tag, val))
  1348. return 0;
  1349. return 1;
  1350. }
  1351. static void ASN1CALL ASN1Free_Pkcs_8ShroudedKeyBag(Pkcs_8ShroudedKeyBag *val)
  1352. {
  1353. if (val) {
  1354. ASN1Free_EncryptedPrivateKeyInfo(val);
  1355. }
  1356. }