utf8 + bom

This commit is contained in:
Zhi Guan
2021-08-04 22:07:50 +08:00
parent a57193836b
commit ae001fbf15
115 changed files with 1362 additions and 965 deletions

View File

@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 2.8.11)
project(GmSSL) project(GmSSL)
set(CMAKE_MACOSX_RPATH 1)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -268,6 +268,8 @@ int asn1_sequence_of_get_next_item(const ASN1_SEQUENCE_OF *a, const uint8_t **ne
int asn1_sequence_of_get_count(const ASN1_SEQUENCE_OF *a, size_t *count); int asn1_sequence_of_get_count(const ASN1_SEQUENCE_OF *a, size_t *count);
int asn1_check(int expr);
#if __cplusplus #if __cplusplus
} }

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -47,88 +47,6 @@
*/ */
/*
ContentInfo ::= SEQUENCE {
contentType OBJECT IDENTIFIER,
content [0] EXPLICIT ANY OPTIONAL
}
data 1.2.156.10197.6.1.4.2.1
data ::= OCTET STRING
SignedData ::= SEQUENCE {
version INTEGER (1),
digestAlgorithms SET OF AlgorithmIdentifier,
contentInfo ContentInfo,
certificates [0] IMPLICIT SET OF Certificate OPTIONAL,
crls [1] IMPLICIT SET OF CertificateRevocationList OPTIONAL,
signerInfos SET OF SignerInfo
}
SignerInfo ::= SEQUENCE {
version INTEGER (1),
issuerAndSerialNumber IssuerAndSerialNumber,
digestAlgorithm AlgorithmIdentifier,
authenticatedAttributes [0] IMPLICIT SET OF Attribute OPTINOAL,
digestEncryptionAlgorithm AlgorithmIdentifier,
encryptedDigest OCTET STRING,
unauthenticatedAttributes [1] IMPLICIT SET OF Attribute OPTINOAL,
}
EnvelopedData ::= SEQUENCE {
version INTEGER (1),
recipientInfos SET OF RecipientInfo,
encryptedContentInfo EncryptedContentInfo
}
EncryptedContentInfo ::= SEQUENCE {
contentType OBJECT IDENTIFIER,
contentEncryptionAlgorithm AlgorithmIdentifier,
encryptedContent [0] IMPLICIT OCTET STRING OPTIONAL,
sharedInfo1 [1] IMPLICIT OCTET STRING OPTIONAL,
sharedInfo2 [2] IMPLICIT OCTET STRING OPTIONAL,
}
RecipientInfo ::= SEQUENCE {
version INTEGER (1),
issuerAndSerialNumber IssuerAndSerialNumber,
keyEncryptionAlgorithm AlgorithmIdentifier,
encryptedKey OCTET STRING
}
SignedAndEnvelopedData ::= SEQUENCE {
version INTEGER (1),
recipientInfos SET OF RecipientInfo,
digestAlgorithms SET OF AlgorithmIdentifier,
encryptedContentInfo EncryptedContentInfo,
certificates [0] IMPLICIT SET OF Certificate OPTIONAL,
crls [1] IMPLICIT SET OF CertificateRevocationList OPTIONAL,
signerInfos SET OF SignerInfo
}
EncryptedData ::= SEQUENCE {
version INTEGER (1),
encryptedContentInfo EncryptedContentInfo
}
KeyAgreementInfo ::= SEQUENCE {
version INTEGER (1),
tempPublicKeyR SM2PublicKey,
userCertificate Certificate,
userID OCTET STRING
}
*/
#ifndef GMSSL_CMS_H #ifndef GMSSL_CMS_H
#define GMSSL_CMS_H #define GMSSL_CMS_H
@@ -149,8 +67,6 @@ enum {
CMS_version = 1, CMS_version = 1,
}; };
typedef enum { typedef enum {
CMS_data = 1, CMS_data = 1,
CMS_signed_data = 2, CMS_signed_data = 2,
@@ -163,11 +79,7 @@ typedef enum {
/*
IssuerAndSerialNumber ::= SEQUENCE {
issuer Name,
serialNumber INTEGER }
*/
int cms_issuer_and_serial_number_from_certificate(const X509_NAME **issuer, int cms_issuer_and_serial_number_from_certificate(const X509_NAME **issuer,
const uint8_t **serial_number, size_t *serial_number_len, const uint8_t **serial_number, size_t *serial_number_len,
const X509_CERTIFICATE *cert); const X509_CERTIFICATE *cert);
@@ -211,9 +123,9 @@ int cms_signer_info_to_der(const X509_NAME *issuer,
int cms_signer_info_from_der(X509_NAME *issuer, int cms_signer_info_from_der(X509_NAME *issuer,
const uint8_t **serial_number, size_t *serial_number_len, const uint8_t **serial_number, size_t *serial_number_len,
int *digest_algor, uint32_t *nodes, size_t *nodes_count, int *digest_algor,
const uint8_t **authed_attrs, size_t *authed_attrs_len, const uint8_t **authed_attrs, size_t *authed_attrs_len,
int *sign_algor, uint32_t *sign_algor_nodes, size_t *sign_algor_nodes_count, int *sign_algor,
const uint8_t **enced_digest, size_t *enced_digest_len, const uint8_t **enced_digest, size_t *enced_digest_len,
const uint8_t **unauthed_attrs, size_t *unauthed_attrs_len, const uint8_t **unauthed_attrs, size_t *unauthed_attrs_len,
const uint8_t **in, size_t *inlen); const uint8_t **in, size_t *inlen);
@@ -267,7 +179,26 @@ int cms_sign(const SM2_KEY *sign_keys,
const uint8_t **crls, size_t *crls_lens, size_t crls_count, const uint8_t **crls, size_t *crls_lens, size_t crls_count,
uint8_t *content_info, size_t *content_info_len); uint8_t *content_info, size_t *content_info_len);
int cms_encrypt(const uint8_t key[16], const uint8_t *in, size_t inlen,
uint8_t *out, size_t *outlen);
int cms_decrypt(const uint8_t key[16], const uint8_t *in, size_t inlen,
int *content_type, uint8_t *out, size_t *outlen,
const uint8_t **shared_info1, size_t *shared_info1_len,
const uint8_t **shared_info2, size_t *shared_info2_len);
int cms_enced_content_info_to_der(int enc_algor, const uint8_t *enc_iv, size_t enc_iv_len,
int content_type, const uint8_t *enced_content, size_t enced_content_len,
const uint8_t *shared_info1, size_t shared_info1_len,
const uint8_t *shared_info2, size_t shared_info2_len,
uint8_t **out, size_t *outlen);
int cms_enced_content_info_from_der(int *content_type,
int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len,
const uint8_t **enced_content, size_t *enced_content_len,
const uint8_t **shared_info1, size_t *shared_info1_len,
const uint8_t **shared_info2, size_t *shared_info2_len,
const uint8_t **in, size_t *inlen);
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
OCSPSigning * Redistribution and use in source and binary forms, with or without OCSPSigning * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2016 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2016 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -168,23 +168,35 @@ AlgorithmIdentifier ::= SEQUENCE {
当 algorithm 为 ECDSA/SM2 时parameters 为空 当 algorithm 为 ECDSA/SM2 时parameters 为空
当 algorithm 为 RSA 时parameters 为 ASN1_NULL 对象 当 algorithm 为 RSA 时parameters 为 ASN1_NULL 对象
*/ */
int x509_signature_algor_to_der(int oid, uint8_t **out, size_t *outlen); int x509_signature_algor_to_der(int algor, uint8_t **out, size_t *outlen);
int x509_signature_algor_from_der(int *oid, const uint8_t **in, size_t *inlen);
const char *x509_digest_algor_name(int oid); int x509_signature_algor_from_der(
int *algor, uint32_t algor_nodes[32], size_t *algor_nodes_count,
const uint8_t **in, size_t *inlen);
const char *x509_digest_algor_name(int algor);
int x509_digest_algor_to_der(int oid, uint8_t **out, size_t *outlen); int x509_digest_algor_to_der(int oid, uint8_t **out, size_t *outlen);
int x509_digest_algor_from_der(int *oid, uint32_t *nodes, size_t *nodes_count, int x509_digest_algor_from_der(int *oid, uint32_t *nodes, size_t *nodes_count,
const uint8_t **in, size_t *inlen); const uint8_t **in, size_t *inlen);
const char *x509_encryption_algor_name(int algor);
int x509_encryption_algor_to_der(int cipher, const uint8_t *iv, size_t ivlen, int x509_encryption_algor_to_der(int cipher, const uint8_t *iv, size_t ivlen,
uint8_t **out, size_t *outlen); uint8_t **out, size_t *outlen);
int x509_encryption_algor_from_der(int *cipher,
int x509_encryption_algor_from_der(
int *algor, uint32_t algor_nodes[32], size_t *algor_nodes_count,
const uint8_t **iv, size_t *ivlen, const uint8_t **iv, size_t *ivlen,
const uint8_t **in, size_t *inlen); const uint8_t **in, size_t *inlen);
int x509_public_key_encryption_algor_to_der(int algor, uint8_t **out, size_t *outlen); int x509_public_key_encryption_algor_to_der(int algor, uint8_t **out, size_t *outlen);
int x509_public_key_encryption_algor_from_der(int *algor, int x509_public_key_encryption_algor_from_der(int *algor,
uint32_t *nodes, size_t *nodes_count, uint32_t *nodes, size_t *nodes_count,
const uint8_t *params, size_t *params_len, const uint8_t **params, size_t *params_len,
const uint8_t **in, size_t *inlen); const uint8_t **in, size_t *inlen);

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -1032,3 +1032,11 @@ int asn1_sequence_of_get_count(const ASN1_SEQUENCE_OF *a, size_t *count)
} }
return 1; return 1;
} }
int asn1_check(int expr)
{
if (expr)
return 1;
error_print();
return -1;
}

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

1816
src/cms.c

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* ==================================================================== /* ====================================================================
* Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* ==================================================================== /* ====================================================================
* Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* ==================================================================== /* ====================================================================
* Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* ==================================================================== /* ====================================================================
* Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* ==================================================================== /* ====================================================================
* Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -156,34 +156,41 @@ int x509_encryption_algor_to_der(int cipher, const uint8_t *iv, size_t ivlen,
return 1; return 1;
} }
int x509_encryption_algor_from_der(int *cipher, const char *x509_encryption_algor_name(int algor)
{
switch (algor) {
case OID_sm4_cbc: return "sm4-cbc";
}
return NULL;
}
int x509_encryption_algor_from_der(int *algor, uint32_t nodes[32], size_t *nodes_count,
const uint8_t **iv, size_t *ivlen, const uint8_t **iv, size_t *ivlen,
const uint8_t **in, size_t *inlen) const uint8_t **in, size_t *inlen)
{ {
int ret; int ret;
const uint8_t *data; const uint8_t *data;
size_t datalen; size_t datalen;
uint32_t nodes[32];
size_t nodes_count;
if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) {
if (ret < 0) error_print(); if (ret < 0) error_print();
return ret; return ret;
} }
if (asn1_object_identifier_from_der(cipher, nodes, &nodes_count, &data, &datalen) != 1 if (asn1_object_identifier_from_der(algor, nodes, nodes_count, &data, &datalen) != 1
|| asn1_octet_string_from_der(iv, ivlen, &data, &datalen) != 1 || asn1_octet_string_from_der(iv, ivlen, &data, &datalen) != 1
|| datalen > 0) { || datalen > 0) {
error_print(); error_print();
return -1; return -1;
} }
if (*cipher == OID_undef) { if (*algor == OID_undef) {
if (nodes_count == sm4_cbc_nodes_count if (*nodes_count == sm4_cbc_nodes_count
&& memcmp(nodes, sm4_cbc_nodes, sizeof(sm4_cbc_nodes)) == 0) { && memcmp(nodes, sm4_cbc_nodes, sizeof(sm4_cbc_nodes)) == 0) {
*cipher = OID_sm4_cbc; *algor = OID_sm4_cbc;
} else { } else {
size_t i; size_t i;
error_puts("unknown cipher oid :"); error_puts("unknown cipher oid :");
for (i = 0; i < nodes_count; i++) { for (i = 0; i < *nodes_count; i++) {
fprintf(stderr, " %d", nodes[i]); fprintf(stderr, " %d", nodes[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@@ -252,19 +259,18 @@ int x509_signature_algor_to_der(int oid, uint8_t **out, size_t *outlen)
return 1; return 1;
} }
int x509_signature_algor_from_der(int *oid, const uint8_t **in, size_t *inlen) int x509_signature_algor_from_der(int *algor, uint32_t nodes[32], size_t nodes_count,
const uint8_t **in, size_t *inlen)
{ {
int ret; int ret;
const uint8_t *data; const uint8_t *data;
size_t datalen; size_t datalen;
uint32_t nodes[32];
size_t nodes_count;
int has_null_obj; int has_null_obj;
if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) {
return ret; return ret;
} }
if (asn1_object_identifier_from_der(oid, nodes, &nodes_count, &data, &datalen) != 1) { if (asn1_object_identifier_from_der(algor, nodes, &nodes_count, &data, &datalen) != 1) {
error_print(); error_print();
return -1; return -1;
} }
@@ -278,7 +284,7 @@ int x509_signature_algor_from_der(int *oid, const uint8_t **in, size_t *inlen)
return -1; return -1;
} }
switch (*oid) { switch (*algor) {
//case OID_ecdsa_with_sha1: //case OID_ecdsa_with_sha1:
//case OID_ecdsa_with_sha224 //case OID_ecdsa_with_sha224
//case OID_ecdsa_with_sha256: //case OID_ecdsa_with_sha256:
@@ -327,7 +333,7 @@ int x509_public_key_encryption_algor_to_der(int algor, uint8_t **out, size_t *ou
} }
int x509_public_key_encryption_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count, int x509_public_key_encryption_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count,
const uint8_t *params, size_t *params_len, const uint8_t **params, size_t *params_len,
const uint8_t **in, size_t *inlen) const uint8_t **in, size_t *inlen)
{ {
int ret; int ret;
@@ -345,17 +351,3 @@ int x509_public_key_encryption_algor_from_der(int *algor, uint32_t *nodes, size_
// FIXME: 我们需要一个读取完整obj的函数 // FIXME: 我们需要一个读取完整obj的函数
return 1; return 1;
} }

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -998,6 +998,8 @@ int x509_tbs_certificate_from_der(X509_TBS_CERTIFICATE *a, const uint8_t **in, s
const uint8_t *serial_number; const uint8_t *serial_number;
const uint8_t *issuer_unique_id = NULL; const uint8_t *issuer_unique_id = NULL;
const uint8_t *subject_unique_id = NULL; const uint8_t *subject_unique_id = NULL;
uint32_t nodes[32];
size_t nodes_count;
if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) {
if (ret < 0) error_print(); if (ret < 0) error_print();
@@ -1005,7 +1007,7 @@ int x509_tbs_certificate_from_der(X509_TBS_CERTIFICATE *a, const uint8_t **in, s
} }
if (x509_version_from_der(&a->version, &data, &datalen) != 1 if (x509_version_from_der(&a->version, &data, &datalen) != 1
|| asn1_integer_from_der(&serial_number, &a->serial_number_len, &data, &datalen) != 1 || asn1_integer_from_der(&serial_number, &a->serial_number_len, &data, &datalen) != 1
|| x509_signature_algor_from_der(&a->signature_algor, &data, &datalen) != 1 || x509_signature_algor_from_der(&a->signature_algor, nodes, &nodes_count, &data, &datalen) != 1
|| x509_name_from_der(&a->issuer, &data, &datalen) != 1 || x509_name_from_der(&a->issuer, &data, &datalen) != 1
|| x509_validity_from_der(&a->validity, &data, &datalen) != 1 || x509_validity_from_der(&a->validity, &data, &datalen) != 1
|| x509_name_from_der(&a->subject, &data, &datalen) != 1 || x509_name_from_der(&a->subject, &data, &datalen) != 1
@@ -1077,6 +1079,8 @@ int x509_certificate_from_der(X509_CERTIFICATE *a, const uint8_t **in, size_t *i
size_t datalen; size_t datalen;
const uint8_t *sig; const uint8_t *sig;
size_t sig_nbits; size_t sig_nbits;
uint32_t nodes[32];
size_t nodes_count;
if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) {
if (ret < 0) error_print(); if (ret < 0) error_print();
@@ -1084,7 +1088,7 @@ int x509_certificate_from_der(X509_CERTIFICATE *a, const uint8_t **in, size_t *i
} }
memset(a, 0, sizeof(X509_CERTIFICATE)); memset(a, 0, sizeof(X509_CERTIFICATE));
if (x509_tbs_certificate_from_der(&a->tbs_certificate, &data, &datalen) != 1 if (x509_tbs_certificate_from_der(&a->tbs_certificate, &data, &datalen) != 1
|| x509_signature_algor_from_der(&a->signature_algor, &data, &datalen) != 1 || x509_signature_algor_from_der(&a->signature_algor, nodes, &nodes_count, &data, &datalen) != 1
|| asn1_bit_string_from_der(&sig, &sig_nbits, &data, &datalen) != 1 || asn1_bit_string_from_der(&sig, &sig_nbits, &data, &datalen) != 1
|| datalen > 0) { || datalen > 0) {
error_print(); error_print();
@@ -1263,13 +1267,15 @@ int x509_cert_request_from_der(X509_CERT_REQUEST *a, const uint8_t **in, size_t
size_t datalen; size_t datalen;
const uint8_t *sig; const uint8_t *sig;
size_t siglen; size_t siglen;
uint32_t nodes[32];
size_t nodes_count;
if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) {
if (ret < 0) error_print(); if (ret < 0) error_print();
return ret; return ret;
} }
if (x509_cert_request_info_from_der(&a->req_info, &data, &datalen) != 1 if (x509_cert_request_info_from_der(&a->req_info, &data, &datalen) != 1
|| x509_signature_algor_from_der(&a->signature_algor, &data, &datalen) != 1 || x509_signature_algor_from_der(&a->signature_algor, nodes, &nodes_count, &data, &datalen) != 1
|| x509_signature_copy_from_der(128, a->signature, &a->signature_len, &data, &datalen) != 1 || x509_signature_copy_from_der(128, a->signature, &a->signature_len, &data, &datalen) != 1
|| datalen > 0) { || datalen > 0) {
error_print(); error_print();

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2015 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2015 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* ==================================================================== /* ====================================================================
* Copyright (c) 2015 - 2019 The GmSSL Project. All rights reserved. * Copyright (c) 2015 - 2019 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* ==================================================================== /* ====================================================================
* Copyright (c) 2015 - 2019 The GmSSL Project. All rights reserved. * Copyright (c) 2015 - 2019 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -53,6 +53,7 @@
#include <gmssl/x509.h> #include <gmssl/x509.h>
#include <gmssl/rand.h> #include <gmssl/rand.h>
#include <gmssl/error.h> #include <gmssl/error.h>
#include <gmssl/sm4.h>
#include <gmssl/cms.h> #include <gmssl/cms.h>
static int test_cms_data(void) static int test_cms_data(void)
@@ -99,9 +100,85 @@ static int test_cms_sign(void)
} }
static int test_cms_enced_content_info(void)
{
uint8_t buf[512];
uint8_t *p = buf;
const uint8_t *cp = buf;
size_t len = 0;
uint8_t iv[16];
uint8_t enced_content[30];
if (cms_enced_content_info_to_der(OID_sm4_cbc, iv, sizeof(iv),
CMS_data, enced_content, sizeof(enced_content),
NULL, 0,
NULL, 0,
&p, &len) != 1) {
error_print();
return -1;
}
int content_type;
int enc_algor;
const uint8_t *enc_iv;
size_t enc_iv_len;
const uint8_t *penced_content;
size_t enced_content_len;
const uint8_t *shared_info1, *shared_info2;
size_t shared_info1_len, shared_info2_len;
if (cms_enced_content_info_from_der(&content_type,
&enc_algor, &enc_iv, &enc_iv_len,
&penced_content, &enced_content_len,
&shared_info1, &shared_info1_len,
&shared_info2, &shared_info2_len,
&cp, &len) != 1) {
error_print();
return -1;
}
return 1;
}
static int test_cms_encrypt(void)
{
uint8_t key[16];
uint8_t msg[] = "Hello world!";
uint8_t cbuf[512];
uint8_t mbuf[512];
size_t clen, mlen;
int content_type = 0;
const uint8_t *shared_info1 = NULL;
const uint8_t *shared_info2 = NULL;
size_t shared_info1_len, shared_info2_len;
if (cms_encrypt(key, msg, sizeof(msg), cbuf, &clen) != 1) {
error_print();
return -1;
}
format_bytes(stderr, 0, 0, "EncryptedData\n", cbuf, clen);
if (cms_decrypt(key, cbuf, clen, &content_type, mbuf, &mlen,
&shared_info1, &shared_info1_len,
&shared_info2, &shared_info2_len) != 1) {
error_print();
return -1;
}
return 1;
}
int main(void) int main(void)
{ {
test_cms_data(); // 很可能x509_algor.c中有错误
test_cms_sign(); test_cms_enced_content_info();
//test_cms_encrypt();
//test_cms_data();
//test_cms_sign();
return 0; return 0;
} }

View File

@@ -125,6 +125,8 @@ static int test_x509_signature_algor(int oid)
int err = 0; int err = 0;
int tests[] = {OID_sm2sign_with_sm3, OID_rsasign_with_sm3}; int tests[] = {OID_sm2sign_with_sm3, OID_rsasign_with_sm3};
int val; int val;
uint32_t nodes[32];
size_t nodes_count;
uint8_t buf[128]; uint8_t buf[128];
const uint8_t *cp = buf; const uint8_t *cp = buf;
uint8_t *p = buf; uint8_t *p = buf;
@@ -145,7 +147,7 @@ static int test_x509_signature_algor(int oid)
printf("\n"); printf("\n");
} }
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
if (x509_signature_algor_from_der(&val, &cp, &len) != 1) { if (x509_signature_algor_from_der(&val, nodes, &nodes_count, &cp, &len) != 1) {
error_print(); error_print();
err++; err++;
goto end; goto end;

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

Some files were not shown because too many files have changed in this diff Show More