1 /* 2 * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the License); you may 5 * not use this file except in compliance with the License. 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 */ 9 10 11 #ifndef GMSSL_X509_ALG_H 12 #define GMSSL_X509_ALG_H 13 14 15 #include <time.h> 16 #include <string.h> 17 #include <stdint.h> 18 #include <stdlib.h> 19 #include <gmssl/sm2.h> 20 #include <gmssl/oid.h> 21 #include <gmssl/asn1.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* 28 AlgorithmIdentifier ::= SEQUENCE { 29 algorithm OBJECT IDENTIFIER, 30 parameters ANY } 31 */ 32 33 const char *x509_digest_algor_name(int oid); 34 int x509_digest_algor_from_name(const char *name); 35 int x509_digest_algor_from_der(int *oid, const uint8_t **in, size_t *inlen); 36 int x509_digest_algor_to_der(int oid, uint8_t **out, size_t *outlen); 37 int x509_digest_algor_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen); 38 39 const char *x509_encryption_algor_name(int oid); 40 int x509_encryption_algor_from_name(const char *name); 41 int x509_encryption_algor_from_der(int *oid, const uint8_t **iv, size_t *ivlen, const uint8_t **in, size_t *inlen); 42 int x509_encryption_algor_to_der(int oid, const uint8_t *iv, size_t ivlen, uint8_t **out, size_t *outlen); 43 int x509_encryption_algor_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen); 44 45 #define X509_ALGOR_ALLOW_EC_NULL_PARAM 1 46 const char *x509_signature_algor_name(int oid); 47 int x509_signature_algor_from_name(const char *name); 48 int x509_signature_algor_from_der(int *oid, const uint8_t **in, size_t *inlen); 49 int x509_signature_algor_to_der(int oid, uint8_t **out, size_t *outlen); 50 int x509_signature_algor_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen); 51 52 const char *x509_public_key_encryption_algor_name(int oid); 53 int x509_public_key_encryption_algor_from_name(const char *name); 54 int x509_public_key_encryption_algor_from_der(int *oid, const uint8_t **params, size_t *params_len, const uint8_t **in, size_t *inlen); 55 int x509_public_key_encryption_algor_to_der(int oid, uint8_t **out, size_t *outlen); 56 int x509_public_key_encryption_algor_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen); 57 58 const char *x509_public_key_algor_name(int oid); 59 int x509_public_key_algor_from_name(const char *name); 60 int x509_public_key_algor_to_der(int oid, int curve, uint8_t **out, size_t *outlen); 61 int x509_public_key_algor_from_der(int *oid, int *curve_or_null, const uint8_t **in, size_t *inlen); 62 int x509_public_key_algor_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen); 63 64 65 66 #ifdef __cplusplus 67 } 68 #endif 69 #endif 70