Commit 5ddd1f4c authored by ASN.1 Documenter's avatar ASN.1 Documenter
Browse files

add certidx tool

parent f7028d32
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -10,10 +10,11 @@ PROJECTROOT = ..
CSHAREDDIR       = $(PROJECTROOT)/cshared
CSHAREDDIR       = $(PROJECTROOT)/cshared
PROJECT          = certgen
PROJECT          = certgen
DEBUG            = yes
DEBUG            = yes
bins             = certgen keygen
bins             = certgen keygen certidx
sources         := ecc_openssl.c mkgmtime.c
sources         := ecc_openssl.c mkgmtime.c
sources-certgen := certgen.c
sources-certgen := certgen.c
sources-keygen  := keygen.c
sources-keygen  := keygen.c
sources-certidx := certidx.c cert_utils.c
cflags          += -Wno-pointer-sign -Wno-enum-compare
cflags          += -Wno-pointer-sign -Wno-enum-compare
sources-WIN32   := applink.c
sources-WIN32   := applink.c
#sources-CYGWIN := applink.c
#sources-CYGWIN := applink.c
+569 −0

File added.

Preview size limit exceeded, changes collapsed.

certgen/cert_utils.c

0 → 100755
+40 −0
Original line number Original line Diff line number Diff line
#include "asn_application.h"
#include "EtsiTs103097Certificate.h"

HashAlgorithm_t CertificateWholeHashAlgorithm(const EtsiTs103097Certificate_t * const cert, const char * name)
{
    HashAlgorithm_t alg;
    
    if(cert->issuer.present == IssuerIdentifier_PR_self){
        alg = cert->issuer.choice.self;
    } else if(cert->type == CertificateType_implicit){
        switch(cert->issuer.present){
            case IssuerIdentifier_PR_sha384AndDigest:
                alg = HashAlgorithm_sha384;
                break;
            case IssuerIdentifier_PR_sha256AndDigest:
                alg = HashAlgorithm_sha256;
                break;
            default:
                if(name) fprintf(stderr, "%s: ERROR: Unknow issuer hash algorithm\n", name);
                return -1;
        }
    } else if(cert->type == CertificateType_explicit){
        switch(cert->toBeSigned.verifyKeyIndicator.choice.verificationKey.present){
            case PublicVerificationKey_PR_ecdsaNistP256:
            case PublicVerificationKey_PR_ecdsaBrainpoolP256r1:
                alg = HashAlgorithm_sha256;
                break;
            case PublicVerificationKey_PR_ecdsaBrainpoolP384r1:
                alg = HashAlgorithm_sha384;
                break;
            default:
                if(name) fprintf(stderr, "%s: ERROR: Unknow verification key algorithm\n", name);
                return -1;
        }
    } else {
        if(name) fprintf(stderr, "%s: ERROR: Unknow certificate type\n", name);
        return -1;
    }
    return alg;
}
 No newline at end of file
+12 −12
Original line number Original line Diff line number Diff line
@@ -499,23 +499,23 @@
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
    <LinkIncremental>true</LinkIncremental>
    <OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
    <OutDir>$(SolutionDir)build\MSVC-$(PlatformName)-$(Configuration)\</OutDir>
    <IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
    <IntDir>$(SolutionDir)build\MSVC-$(PlatformName)-$(Configuration)\obj\$(ProjectName)\</IntDir>
  </PropertyGroup>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
    <LinkIncremental>true</LinkIncremental>
    <OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
    <OutDir>$(SolutionDir)build\MSVC-$(PlatformName)-$(Configuration)\</OutDir>
    <IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
    <IntDir>$(SolutionDir)build\MSVC-$(PlatformName)-$(Configuration)\obj\$(ProjectName)\</IntDir>
  </PropertyGroup>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
    <LinkIncremental>false</LinkIncremental>
    <OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
    <OutDir>$(SolutionDir)build\MSVC-$(PlatformName)-$(Configuration)\</OutDir>
    <IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
    <IntDir>$(SolutionDir)build\MSVC-$(PlatformName)-$(Configuration)\obj\$(ProjectName)\</IntDir>
  </PropertyGroup>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
    <LinkIncremental>false</LinkIncremental>
    <OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
    <OutDir>$(SolutionDir)build\MSVC-$(PlatformName)-$(Configuration)\</OutDir>
    <IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
    <IntDir>$(SolutionDir)build\MSVC-$(PlatformName)-$(Configuration)\obj\$(ProjectName)\</IntDir>
  </PropertyGroup>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
    <ClCompile>
@@ -530,7 +530,7 @@
      <SubSystem>Console</SubSystem>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalLibraryDirectories>C:\OpenSSL\Win32\lib\VC\static</AdditionalLibraryDirectories>
      <AdditionalLibraryDirectories>C:\OpenSSL\Win32\lib\VC\static</AdditionalLibraryDirectories>
      <AdditionalDependencies>libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalDependencies>libcrypto32MTd.lib;libssl32MTd.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
    </Link>
  </ItemDefinitionGroup>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -546,7 +546,7 @@
      <SubSystem>Console</SubSystem>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalLibraryDirectories>C:\Tools\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
      <AdditionalLibraryDirectories>C:\Tools\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
      <AdditionalDependencies>ws2_32.lib;libcrypto64MDd.lib;libssl64MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalDependencies>ws2_32.lib;libcrypto64MTd.lib;libssl64MTd.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
    </Link>
  </ItemDefinitionGroup>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -565,7 +565,7 @@
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <OptimizeReferences>true</OptimizeReferences>
      <AdditionalDependencies>libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalDependencies>libcrypto32MT.lib;libssl32MT.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>C:\OpenSSL\Win32\lib\VC\static</AdditionalLibraryDirectories>
      <AdditionalLibraryDirectories>C:\OpenSSL\Win32\lib\VC\static</AdditionalLibraryDirectories>
    </Link>
    </Link>
  </ItemDefinitionGroup>
  </ItemDefinitionGroup>
@@ -585,7 +585,7 @@
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <OptimizeReferences>true</OptimizeReferences>
      <AdditionalDependencies> ws2_32.lib;libcrypto64MD.lib;libssl64MD.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalDependencies> ws2_32.lib;libcrypto64MT.lib;libssl64MT.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>C:\Tools\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
      <AdditionalLibraryDirectories>C:\Tools\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
    </Link>
    </Link>
  </ItemDefinitionGroup>
  </ItemDefinitionGroup>

certgen/certidx.c

0 → 100755
+351 −0
Original line number Original line Diff line number Diff line
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include "../cshared/copts.h"
#include "../cshared/cstr.h"

#include "EtsiTs103097Certificate.h"

#if defined(CYGWIN) || !defined(WIN32)
#include <glob.h>

#ifndef _GLOB_H_
#define _GLOB_H_
typedef struct {
	size_t gl_pathc;	/* Count of total paths so far. */
	size_t gl_matchc;	/* Count of paths matching pattern. */
	size_t gl_offs;		/* Reserved at beginning of gl_pathv. */
	int gl_flags;		/* Copy of flags parameter to glob. */
	char **gl_pathv;	/* List of paths matching pattern. */
}glob_t;

int	 glob (const char * pattern,  int flags , int (*)(const char *, int), glob_t * gl);
void globfree (glob_t *);
int	 glob_pattern_p (const char *, int);

#endif // _GLOB_H_
#endif

#include "ecc_api.h"

#define CERT_MAX_SIZE 0x10000

static const char * _outPath = "-";
static int _canonicalize = 1;
static FILE * _out;

static copt_t _options [] = {
	{ "h?", "help", COPT_HELP, NULL,                 "Print this help page" },
	{ "o", "out", COPT_STR, (void*)&_outPath,         "Output path [stdout by default]" },
	{ "c", "no-canonicalize", COPT_BOOLI, (void*)&_canonicalize,         "No canonicalize" },
	{ NULL, NULL, COPT_END, NULL, NULL }
};

char * _bin2hex(char * hex, size_t hlen, const char * bin, size_t blen);

HashAlgorithm_t CertificateWholeHashAlgorithm(const EtsiTs103097Certificate_t * const cert, const char * name);

int process_cert(const pchar_t * name, uint8_t * buf, const uint8_t * end);

static ecc_curve_id _pk_type_to_curveid[] = {
	0,
	ecies_nistp256,       //Signature_PR_ecdsaNistP256Signature,
	ecies_brainpoolp256r, //Signature_PR_ecdsaBrainpoolP256r1Signature,
	ecies_brainpoolp384r  //Signature_PR_ecdsaBrainpoolP384r1Signature
};
/*
static const char * _pk_curve_names[] = {
	"nistp256",
	"brainpoolp256r",
	"brainpoolp384r",
	"unsupported"
};

static ecc_curve_id _pk_type_to_hashid[] = {
	0,
	sha_256,       //Signature_PR_ecdsaNistP256Signature,
	sha_256, //Signature_PR_ecdsaBrainpoolP256r1Signature,
	sha_384  //Signature_PR_ecdsaBrainpoolP384r1Signature
};

static size_t _pk_type_to_hashsize[] = {
	0,
	sha256_hash_size,       //Signature_PR_ecdsaNistP256Signature,
	sha256_hash_size, //Signature_PR_ecdsaBrainpoolP256r1Signature,
	sha384_hash_size  //Signature_PR_ecdsaBrainpoolP384r1Signature
};

static asn_dec_rval_t Signature_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
	const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
	void **struct_ptr, const void *buf_ptr, size_t size);
static asn_dec_rval_t EcdsaSignature_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
	const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
	void **struct_ptr, const void *buf_ptr, size_t size);
static asn_dec_rval_t EccCurvePoint_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
	const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
	void **struct_ptr, const void *buf_ptr, size_t size);
static asn_dec_rval_t PublicKey_oer_decoder(const struct asn_codec_ctx_s* opt_codec_ctx,
    const struct asn_TYPE_descriptor_s* td, const asn_oer_constraints_t* constraints,
    void** struct_ptr, const void* buf_ptr, size_t size);
*/
int main(int argc, char ** argv)
{
	//parse options
	argc = coptions(argc, argv, COPT_HELP_NOVALUES , _options);
	if(argc < 2){
		if(argc < 0 && (0-argc)<((sizeof(_options)/sizeof(_options[0]))-1)){
			printf("Unknown option %s\n", argv[0-argc]);
		}
		const char * a = strrchr(argv[0], '/');
		if (a == NULL) a = argv[0];
		coptions_help(stdout, a, COPT_HELP_NOVALUES, _options, "... certificate files ...");
		return -1;
	}

	if(ecc_api_init()){
		fprintf(stderr, "Cannot initialize ECC engine\n");
		return -1;
	}

    if(!cstrequal("-", _outPath)){
        _out = fopen(_outPath, "wb");
        if(_out == NULL){
            perror(_outPath);
            return -1;
        }
    }else{
        _out = stdout;
    }
    /*
    static asn_TYPE_operation_t signatureOps, ecdsaSignatureOps, eccCurvePointOps,
                                verificationKeyOps, encryptionKeyOps;
    signatureOps = *asn_DEF_Signature.op;
    asn_DEF_Signature.op = &signatureOps;
 	signatureOps.oer_decoder = Signature_oer_decoder;

    ecdsaSignatureOps = *asn_DEF_EcdsaP256Signature.op;
    asn_DEF_EcdsaP256Signature.op = &ecdsaSignatureOps;
    asn_DEF_EcdsaP384Signature.op = &ecdsaSignatureOps;
	ecdsaSignatureOps.oer_decoder = EcdsaSignature_oer_decoder;

    eccCurvePointOps = *asn_DEF_EccP256CurvePoint.op;
    asn_DEF_EccP256CurvePoint.op = &eccCurvePointOps;
    asn_DEF_EccP384CurvePoint.op = &eccCurvePointOps;
    eccCurvePointOps.oer_decoder = EccCurvePoint_oer_decoder;

    verificationKeyOps = *asn_DEF_PublicVerificationKey.op;
    asn_DEF_PublicVerificationKey.op = &verificationKeyOps;
    verificationKeyOps.oer_decoder = PublicKey_oer_decoder;

    encryptionKeyOps = *asn_DEF_BasePublicEncryptionKey.op;
    asn_DEF_BasePublicEncryptionKey.op = &encryptionKeyOps;
    encryptionKeyOps.oer_decoder = PublicKey_oer_decoder;
    */

	char * buf = malloc(CERT_MAX_SIZE);
	char * ebuf;

    for(int argi=1; argi<argc; argi++){
    	ebuf = cstrnload(buf, CERT_MAX_SIZE, argv[argi]);
        if(ebuf && (ebuf - buf) > 0){
            const pchar_t* fname = cstrlastpathelement(argv[argi]);
            *cstrpathextension(fname) = 0;
            process_cert(fname, buf, ebuf);
        }else{
            // check if it is a mask
#if defined(_GLOB_H_)
            glob_t gl = {0};
            if(0 == glob( argv[argi], 0, NULL, &gl )){
                for (size_t i=0; i<gl.gl_pathc; i++){
                    ebuf = cstrnload(buf, CERT_MAX_SIZE, gl.gl_pathv[i]);
                    if (ebuf && (ebuf - buf) > 0) {
                        const pchar_t* fname = cstrlastpathelement(gl.gl_pathv[i]);
                        *cstrpathextension(fname) = 0;
                        process_cert(fname, buf, ebuf);
                    }
                }
                globfree (&gl);
            }
#elif defined(WIN32)
// try use the FindFile approach
            WIN32_FIND_DATA fd;
            size_t len = cstrlen(argv[argi]);
            pchar_t * path = cstralloc(len + MAX_PATH);
            cstrcpy(path, argv[argi]);
            pchar_t * fname = cstrlastpathelement(path);
            HANDLE h = FindFirstFile(path, &fd);
    		if(INVALID_HANDLE_VALUE != h) do {
                cstrcpy(fname, fd.cFileName);
                ebuf = cstrnload(buf, CERT_MAX_SIZE, path);
                if(ebuf && (ebuf - buf) > 0){
                    *cstrpathextension(fname) = 0;
                    process_cert(fname, buf, ebuf);            
                }
            }while(FindNextFile(h, &fd));
            FindClose(h);
#endif
        }
    }
    free(buf);
    return 0;
}

typedef struct its_asn_codec_ctx_s {
    asn_codec_ctx_t ctx;
    ecc_curve_id curve;
    size_t mcount;
    struct {
        uint8_t* ptr;
        size_t   shift;
    }move[8];
}its_asn_codec_ctx_t;

static int update_ecc_curve(ecc_curve_id curve, EccP256CurvePoint_t* p)
{
    if (p->present == EccP256CurvePoint_PR_uncompressedP256 || p->present == EccP256CurvePoint_PR_x_only) {
        void* key = ecc_key_public_set(curve, p->present - 1, p->choice.uncompressedP256.x.buf, p->choice.uncompressedP256.y.buf);
        if (key) {
            int sign;
            char x[48], y[48];
            ecc_key_public(key, &x[0], &y[0], &sign);
            p->present = EccP256CurvePoint_PR_compressed_y_0 + (sign ? 1 : 0);
            ecc_key_free(key);
            return 1;
        }
    }
    return 0;
}

int process_cert(const pchar_t * name, uint8_t * buf, const uint8_t * ebuf)
{
    // determine the hash alg
    EtsiTs103097Certificate_t * cert = NULL;
	asn_dec_rval_t rc_d;
    its_asn_codec_ctx_t ctx = {{0}};
    int updated = 0;
    HashAlgorithm_t halg;
    rc_d = asn_decode(&ctx.ctx, ATS_BASIC_OER, &asn_DEF_EtsiTs103097Certificate, (void**)&cert, buf, ebuf - buf);
	if (rc_d.code != RC_OK){
		fprintf(stderr, "%s: ERROR: failed to load at position %d\n  %.30s\n", name, (int)rc_d.consumed, buf + rc_d.consumed);
		return -1;
	}

    if (_canonicalize) {
        if (cert->toBeSigned.verifyKeyIndicator.present == VerificationKeyIndicator_PR_verificationKey) {
            // use ecdsaBrainpoolP256r1. other variantes has the same structure
            updated += update_ecc_curve(_pk_type_to_curveid[cert->toBeSigned.verifyKeyIndicator.choice.verificationKey.present],
                &cert->toBeSigned.verifyKeyIndicator.choice.verificationKey.choice.ecdsaNistP256);
        }
        else if (cert->toBeSigned.verifyKeyIndicator.present == VerificationKeyIndicator_PR_reconstructionValue) {
            if (cert->toBeSigned.verifyKeyIndicator.choice.reconstructionValue.present != EccP256CurvePoint_PR_compressed_y_0 &&
                cert->toBeSigned.verifyKeyIndicator.choice.reconstructionValue.present != EccP256CurvePoint_PR_compressed_y_1) {
                fprintf(stderr, "%s: ERROR: reconstruction value should be in compressed form\n", name);
                return -1;
            }
        }
        if (cert->toBeSigned.encryptionKey) {
            updated += update_ecc_curve(_pk_type_to_curveid[cert->toBeSigned.encryptionKey->publicKey.present],
                &cert->toBeSigned.encryptionKey->publicKey.choice.eciesNistP256);
        }

        if (cert->signature) {
            if (cert->signature->choice.ecdsaNistP256Signature.rSig.present != EccP256CurvePoint_PR_x_only) {
                cert->signature->choice.ecdsaNistP256Signature.rSig.present = EccP256CurvePoint_PR_x_only;
                updated++;
            }
        }
        if (updated) {
            asn_enc_rval_t rc_e = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_EtsiTs103097Certificate, cert, buf, CERT_MAX_SIZE);
            if (rc_e.encoded < 0) {
                fprintf(stderr, "%s: ERROR: OER encoding failed for canonicalized certificate at type %s\n", name, rc_e.failed_type->name);
                return -1;
            }
            rc_d.consumed = rc_e.encoded;
        }
    }

    halg = CertificateWholeHashAlgorithm(cert, name);

    ASN_STRUCT_FREE(asn_DEF_EtsiTs103097Certificate, cert);

    uint8_t hash[256];
    uint8_t * digest;
    switch(halg){
        case HashAlgorithm_sha256:
            sha256_calculate(&hash[0], buf, rc_d.consumed);
            digest = &hash[32 - 8];
            break;
        case HashAlgorithm_sha384:
            sha384_calculate(&hash[0], buf, rc_d.consumed);
            digest = &hash[48 - 8];
            break;
        default:
            return -1;
    }
    char hex[20];
    * cstr_bin2hex(hex, sizeof(hex), digest, 8) = 0;
    fprintf(_out, "%s %s\n", hex, name);
    return 0;
}
/*
static asn_dec_rval_t Signature_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
	const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
	void **struct_ptr, const void *buf_ptr, size_t size)
{
    its_asn_codec_ctx_t * ctx = (its_asn_codec_ctx_t *)opt_codec_ctx;
    ctx->curve = (*((uint8_t*) buf_ptr)) - 0x80;
    return asn_OP_CHOICE.oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, buf_ptr, size);
}

static asn_dec_rval_t PublicKey_oer_decoder(const struct asn_codec_ctx_s* opt_codec_ctx,
    const struct asn_TYPE_descriptor_s* td, const asn_oer_constraints_t* constraints,
    void** struct_ptr, const void* buf_ptr, size_t size)
{
    its_asn_codec_ctx_t* ctx = (its_asn_codec_ctx_t*)opt_codec_ctx;
    ctx->curve = (*((uint8_t*)buf_ptr)) - 0x80;
    return asn_OP_CHOICE.oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, buf_ptr, size);
}

static asn_dec_rval_t EcdsaSignature_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
	const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
	void **struct_ptr, const void *buf_ptr, size_t size)
{
    uint8_t * b = (uint8_t*) buf_ptr;
    asn_dec_rval_t rc = asn_OP_SEQUENCE.oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, buf_ptr, size);
    // set to x_only
    *b = 0x80;
    return rc;
}

static asn_dec_rval_t EccCurvePoint_oer_decoder(const struct asn_codec_ctx_s *opt_codec_ctx,
	const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints,
	void **struct_ptr, const void *buf_ptr, size_t size)
{
    uint8_t * b = (uint8_t*) buf_ptr;
    asn_dec_rval_t rc = asn_OP_CHOICE.oer_decoder(opt_codec_ctx, td, constraints, struct_ptr, buf_ptr, size);
    EccP256CurvePoint_t * p = (EccP256CurvePoint_t*)*struct_ptr;
    its_asn_codec_ctx_t * ctx = (its_asn_codec_ctx_t *)opt_codec_ctx;
    size_t psize = (td == &asn_DEF_EccP256CurvePoint) ? 32 : 48;

    if(p->present == EccP256CurvePoint_PR_uncompressedP256 || p->present == EccP256CurvePoint_PR_x_only){
        void * key = ecc_key_public_set(ctx->curve, p->present-1, p->choice.uncompressedP256.x.buf, p->choice.uncompressedP256.y.buf);
        if(!key){
            rc.code = RC_FAIL;
        }else{
            int sign;
            char x[48], y[48];
            ecc_key_public(key, &x[0], &y[0], &sign);
            *b = 0x81 + (sign?1:0);
            ecc_key_free(key); 
            if(p->present == EccP256CurvePoint_PR_uncompressedP256){
                // move the rest of the buffer
                ctx->move[ctx->mcount].ptr = b + rc.consumed;
                ctx->move[ctx->mcount].shift = psize;
                ctx->mcount++;
            }
        }
    }
    return rc;
}
*/
 No newline at end of file
Loading