]> git.zerfleddert.de Git - proxmark3-svn/blob - client/crypto/asn1utils.c
2a3fe698bad276a4d4d608ee453d5d23d438dfe4
[proxmark3-svn] / client / crypto / asn1utils.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2018 Merlok
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // asn.1 utils
9 //-----------------------------------------------------------------------------
10
11 #include "asn1utils.h"
12 #include <mbedtls/asn1.h>
13
14 int ecdsa_asn1_get_signature(uint8_t *signature, size_t signaturelen, uint8_t *rval, uint8_t *sval) {
15 if (!signature || !signaturelen || !rval || !sval)
16 return 1;
17
18 int res = 0;
19 unsigned char *p = signature;
20 const unsigned char *end = p + signaturelen;
21 size_t len;
22 mbedtls_mpi xmpi;
23
24 if ((res = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) == 0) {
25 mbedtls_mpi_init(&xmpi);
26 res = mbedtls_asn1_get_mpi(&p, end, &xmpi);
27 if (res) {
28 mbedtls_mpi_free(&xmpi);
29 goto exit;
30 }
31
32 res = mbedtls_mpi_write_binary(&xmpi, rval, 32);
33 mbedtls_mpi_free(&xmpi);
34 if (res)
35 goto exit;
36
37 mbedtls_mpi_init(&xmpi);
38 res = mbedtls_asn1_get_mpi(&p, end, &xmpi);
39 if (res) {
40 mbedtls_mpi_free(&xmpi);
41 goto exit;
42 }
43
44 res = mbedtls_mpi_write_binary(&xmpi, sval, 32);
45 mbedtls_mpi_free(&xmpi);
46 if (res)
47 goto exit;
48
49 // check size
50 if (end != p)
51 return 2;
52 }
53
54 exit:
55 return res;
56 }
57
58 int asn1_print(uint8_t *asn1buf, int level) {
59
60 return 0;
61 }
62
63
Impressum, Datenschutz