added cose_key descriptions

This commit is contained in:
merlokk 2018-11-26 19:22:44 +02:00
commit 0a2f874ac3
2 changed files with 34 additions and 16 deletions

View file

@ -38,8 +38,22 @@ COSEValueNameDesc_t COSEKeyTypeValueDesc[] = {
{4, "Symmetric", "Symmetric Key"}, {4, "Symmetric", "Symmetric Key"},
}; };
COSEValueNameDesc_t *GetCOSEktyElm(int id) {
for (int i = 0; i < ARRAYLEN(COSEKeyTypeValueDesc); i++)
if (COSEKeyTypeValueDesc[i].Value == id)
return &COSEKeyTypeValueDesc[i];
return NULL;
}
const char *GetCOSEktyDescription(int id) {
COSEValueNameDesc_t *elm = GetCOSEktyElm(id);
if (elm)
return elm->Description;
return COSEEmptyStr;
}
// keys // keys
COSEValueTypeNameDesc_t COSEKeyTypeDesc[] = { COSEValueTypeNameDesc_t COSECurvesDesc[] = {
{1, "EC2", "P-256", "NIST P-256 also known as secp256r1"}, {1, "EC2", "P-256", "NIST P-256 also known as secp256r1"},
{2, "EC2", "P-384", "NIST P-384 also known as secp384r1"}, {2, "EC2", "P-384", "NIST P-384 also known as secp384r1"},
{3, "EC2", "P-521", "NIST P-521 also known as secp521r1"}, {3, "EC2", "P-521", "NIST P-521 also known as secp521r1"},
@ -49,6 +63,20 @@ COSEValueTypeNameDesc_t COSEKeyTypeDesc[] = {
{7, "OKP", "Ed448", "Ed448 for use w/ EdDSA only"}, {7, "OKP", "Ed448", "Ed448 for use w/ EdDSA only"},
}; };
COSEValueTypeNameDesc_t *GetCOSECurveElm(int id) {
for (int i = 0; i < ARRAYLEN(COSECurvesDesc); i++)
if (COSECurvesDesc[i].Value == id)
return &COSECurvesDesc[i];
return NULL;
}
const char *GetCOSECurveDescription(int id) {
COSEValueNameDesc_t *elm = GetCOSECurveElm(id);
if (elm)
return elm->Description;
return COSEEmptyStr;
}
// RFC8152 https://www.iana.org/assignments/cose/cose.xhtml#algorithms // RFC8152 https://www.iana.org/assignments/cose/cose.xhtml#algorithms
COSEValueNameDesc_t COSEAlg[] = { COSEValueNameDesc_t COSEAlg[] = {
{-65536, "Unassigned", "Unassigned"}, {-65536, "Unassigned", "Unassigned"},
@ -128,20 +156,6 @@ const char *GetCOSEAlgDescription(int id) {
return COSEEmptyStr; return COSEEmptyStr;
} }
COSEValueNameDesc_t *GetCOSEktyElm(int id) {
for (int i = 0; i < ARRAYLEN(COSEKeyTypeValueDesc); i++)
if (COSEKeyTypeValueDesc[i].Value == id)
return &COSEKeyTypeValueDesc[i];
return NULL;
}
const char *GetCOSEktyDescription(int id) {
COSEValueNameDesc_t *elm = GetCOSEktyElm(id);
if (elm)
return elm->Description;
return COSEEmptyStr;
}
int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public_key) { int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public_key) {
CborParser parser; CborParser parser;
CborValue map; CborValue map;
@ -171,9 +185,12 @@ int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public
if(!res) { if(!res) {
cbor_value_get_int64(&map, &i64); cbor_value_get_int64(&map, &i64);
if(verbose) if(verbose)
PrintAndLog("curve [%lld] %s", (long long)i64, GetCOSEAlgDescription(i64)); PrintAndLog("curve [%lld] %s", (long long)i64, GetCOSECurveDescription(i64));
} }
// plain key
public_key[0] = 0x04;
if(verbose) if(verbose)
PrintAndLog("----------- CBOR decode ----------------"); PrintAndLog("----------- CBOR decode ----------------");

View file

@ -20,6 +20,7 @@
extern const char *GetCOSEAlgName(int id); extern const char *GetCOSEAlgName(int id);
extern const char *GetCOSEAlgDescription(int id); extern const char *GetCOSEAlgDescription(int id);
extern const char *GetCOSEktyDescription(int id); extern const char *GetCOSEktyDescription(int id);
extern const char *GetCOSECurveDescription(int id);
extern int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public_key); extern int COSEGetECDSAKey(uint8_t *data, size_t datalen, bool verbose, uint8_t *public_key);