Skip to content

Commit

Permalink
Merge e941615 into af45a12
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsch committed May 8, 2020
2 parents af45a12 + e941615 commit 11c78e8
Show file tree
Hide file tree
Showing 29 changed files with 715 additions and 604 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -37,7 +37,7 @@ script:
- cmake --version
- git clone --depth 1 git://github.com/cose-wg/Examples Examples
- mkdir build
- cd build && cmake -DCOSE_C_USE_CONTEXT=$USE_CONTEXT -DCOSE_C_USE_MBEDTLS=$USE_EMBEDTLS $CMAKE_OPTIONS $COVERALLS .. && make all test
- cd build && cmake -DCOSE_C_USE_CONTEXT=$USE_CONTEXT -DCOSE_C_USE_MBEDTLS=$USE_EMBEDTLS $CMAKE_OPTIONS $COVERALLS .. && make -k all test

after_success:
- make coveralls
Expand Down
10 changes: 5 additions & 5 deletions include/cose/cose.h
Expand Up @@ -78,7 +78,7 @@ typedef enum {
COSE_mac_object = 97,
COSE_mac0_object = 17,
COSE_recipient_object = -1,
COSE_countersign_object = -2,
COSE_countersign_object = -2
} COSE_object_type;

// Generic functions for the COSE library
Expand Down Expand Up @@ -156,7 +156,7 @@ typedef enum {

COSE_Algorithm_ECDSA_SHA_256 = -7,
COSE_Algorithm_ECDSA_SHA_384 = -35,
COSE_Algorithm_ECDSA_SHA_512 = -36,
COSE_Algorithm_ECDSA_SHA_512 = -36
} COSE_Algorithms;

typedef enum {
Expand Down Expand Up @@ -185,7 +185,7 @@ typedef enum {
COSE_Header_ECDH_STATIC = -2,
COSE_Header_ECDH_EPK = -1,
COSE_Header_ECDH_SPK = -2,
COSE_Header_ECDH_SPK_KID = -3,
COSE_Header_ECDH_SPK_KID = -3

} COSE_Header;

Expand All @@ -200,7 +200,7 @@ typedef enum {
COSE_Key_EC2_X = -2,
COSE_Key_EC2_Y = -3,
COSE_Key_OPK_Curve = -1,
COSE_Key_OPK_X = -2,
COSE_Key_OPK_X = -2
} COSE_Constants;

typedef enum {
Expand All @@ -210,7 +210,7 @@ typedef enum {
COSE_Curve_X25519 = 4,
COSE_Curve_X448 = 5,
COSE_Curve_Ed25519 = 6,
COSE_Curve_Ed448 = 7,
COSE_Curve_Ed448 = 7
} COSE_Curves;

/*
Expand Down
32 changes: 16 additions & 16 deletions src/CMakeLists.txt
@@ -1,6 +1,6 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
message(STATUS "adding GCC/Clang options ")
add_definitions(-std=gnu99 -Wall -Wextra -pedantic)
add_definitions(-Wall -Wextra -pedantic)
if(COSE_C_FATAL_WARNINGS)
add_definitions(-Werror)
endif()
Expand Down Expand Up @@ -28,29 +28,29 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/../include/cose/cose_configure.h.in
${CMAKE_BINARY_DIR}/include/cose/cose_configure.h)

if(COSE_C_USE_MBEDTLS)
set(cose_crypto mbedtls.c)
set(cose_crypto mbedtls.cpp)
else()
set(cose_crypto openssl.c)
set(cose_crypto openssl.cpp)
endif()

set(cose_sources
${PROJECT_SOURCE_DIR}/include/cose/cose.h
${CMAKE_BINARY_DIR}/include/cose/cose_configure.h
cose_crypto.h
cose_int.h
Cose.c
CoseKey.c
CounterSign.c
CounterSign0.c
MacMessage.c
MacMessage0.c
Sign.c
Sign1.c
cbor.c
Encrypt.c
Encrypt0.c
Recipient.c
SignerInfo.c
Cose.cpp
CoseKey.cpp
CounterSign.cpp
CounterSign0.cpp
MacMessage.cpp
MacMessage0.cpp
Sign.cpp
Sign1.cpp
cbor.cpp
Encrypt.cpp
Encrypt0.cpp
Recipient.cpp
SignerInfo.cpp
${cose_crypto})

target_sources(${PROJECT_NAME} PRIVATE ${cose_sources})
Expand Down
20 changes: 13 additions & 7 deletions src/Cose.c → src/Cose.cpp
Expand Up @@ -86,6 +86,11 @@ bool _COSE_Init_From_Object(COSE *pobj,
cn_cbor_errback errState; // = { 0 };
cn_cbor_errback cbor_error;

if (false) {
errorReturn:
return false;
}

#ifdef USE_CBOR_CONTEXT
if (context != NULL) {
pobj->m_allocContext = *context;
Expand Down Expand Up @@ -159,8 +164,6 @@ bool _COSE_Init_From_Object(COSE *pobj,

return true;

errorReturn:
return false;
}

void _COSE_Release(COSE *pcose)
Expand Down Expand Up @@ -207,6 +210,13 @@ HCOSE COSE_Decode(const byte *rgbData,
cn_cbor_errback cbor_err;
HCOSE h;

if (false) {
errorReturn:
// M00TODO - break up the init and allocation below for memory tests.
CN_CBOR_FREE(cbor, context);
return NULL;
}

CHECK_CONDITION(
(rgbData != NULL) && (ptype != NULL), COSE_ERR_INVALID_PARAMETER);

Expand All @@ -220,7 +230,7 @@ HCOSE COSE_Decode(const byte *rgbData,
COSE_ERR_INVALID_PARAMETER);
}
else {
struct_type = cbor->v.uint;
struct_type = (COSE_object_type) cbor->v.uint;
}
*ptype = struct_type;

Expand Down Expand Up @@ -318,10 +328,6 @@ HCOSE COSE_Decode(const byte *rgbData,

return h;

errorReturn:
// M00TODO - break up the init and allocation above for memory tests.
CN_CBOR_FREE(cbor, context);
return NULL;
}

size_t COSE_Encode(HCOSE msg, byte *rgb, size_t ib, size_t cb)
Expand Down
File renamed without changes.
68 changes: 42 additions & 26 deletions src/CounterSign.c → src/CounterSign.cpp
Expand Up @@ -38,7 +38,7 @@ COSE_CounterSign* _COSE_CounterSign_Init_From_Object(cn_cbor* cbor,
{
COSE_CounterSign* pobj = pIn;

cose_errback error = {0};
cose_errback error = {COSE_ERR_NONE};
if (perr == NULL) {
perr = &error;
}
Expand Down Expand Up @@ -252,14 +252,14 @@ bool COSE_CounterSign_SetKey2(HCOSE_COUNTERSIGN hSigner, HCOSE_KEY hKey, cose_er
{
bool fRet = false;
COSE_CounterSign* pSigner = (COSE_CounterSign*)hSigner;
COSE_KEY* pKey = (COSE_KEY*)hKey;

CHECK_CONDITION(IsValidCounterSignHandle(hSigner), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(IsValidKeyHandle(hKey), COSE_ERR_INVALID_HANDLE);

if (pSigner->m_signer.m_pkey != NULL) {
COSE_KEY_Free((HCOSE_KEY) pSigner->m_signer.m_pkey);
}
COSE_KEY* pKey = (COSE_KEY*)hKey;

pSigner->m_signer.m_pkey = pKey;
if (hKey != NULL) {
Expand All @@ -275,11 +275,10 @@ COSE_CounterSign* _COSE_Message_get_countersignature(COSE* pMessage,
int index,
cose_errback* perr)
{
COSE_CounterSign* pCounterSign = pMessage->m_counterSigners;
CHECK_CONDITION(
pMessage->m_counterSigners != NULL, COSE_ERR_INVALID_PARAMETER);

COSE_CounterSign* pCounterSign = pMessage->m_counterSigners;

for (int i = 0; i < index; i++) {
pCounterSign = pCounterSign->m_next;
CHECK_CONDITION(pCounterSign != NULL, COSE_ERR_INVALID_PARAMETER);
Expand Down Expand Up @@ -462,6 +461,11 @@ bool COSE_Signer_CounterSign_validate(HCOSE_SIGNER hSigner,
HCOSE_COUNTERSIGN hCountersignature,
cose_errback* perr)
{
if (false) {
errorReturn:
return false;
}

CHECK_CONDITION(IsValidSignerHandle(hSigner), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
IsValidCounterSignHandle(hCountersignature), COSE_ERR_INVALID_HANDLE);
Expand All @@ -484,8 +488,6 @@ bool COSE_Signer_CounterSign_validate(HCOSE_SIGNER hSigner,

return f;

errorReturn:
return false;
}

/***************************************************************************************************
Expand Down Expand Up @@ -530,6 +532,11 @@ bool COSE_Sign_CounterSign_validate(HCOSE_SIGN hSignMsg,
HCOSE_COUNTERSIGN hCountersignature,
cose_errback* perr)
{
if (false) {
errorReturn:
return false;
}

CHECK_CONDITION(IsValidSignHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
IsValidCounterSignHandle(hCountersignature), COSE_ERR_INVALID_HANDLE);
Expand All @@ -552,8 +559,6 @@ bool COSE_Sign_CounterSign_validate(HCOSE_SIGN hSignMsg,

return f;

errorReturn:
return false;
}
#endif

Expand Down Expand Up @@ -600,6 +605,11 @@ bool COSE_Sign1_CounterSign_validate(HCOSE_SIGN1 hSignMsg,
HCOSE_COUNTERSIGN hCountersignature,
cose_errback* perr)
{
if (false) {
errorReturn:
return false;
}

CHECK_CONDITION(IsValidSign1Handle(hSignMsg), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
IsValidCounterSignHandle(hCountersignature), COSE_ERR_INVALID_HANDLE);
Expand All @@ -621,9 +631,6 @@ bool COSE_Sign1_CounterSign_validate(HCOSE_SIGN1 hSignMsg,
cnProtected, "CounterSignature", perr);

return f;

errorReturn:
return false;
}
#endif

Expand Down Expand Up @@ -670,6 +677,10 @@ bool COSE_Enveloped_CounterSign_validate(HCOSE_ENVELOPED hSignMsg,
HCOSE_COUNTERSIGN hCountersignature,
cose_errback* perr)
{
if (false) {
errorReturn:
return false;
}
CHECK_CONDITION(IsValidEnvelopedHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
IsValidCounterSignHandle(hCountersignature), COSE_ERR_INVALID_HANDLE);
Expand All @@ -691,9 +702,6 @@ bool COSE_Enveloped_CounterSign_validate(HCOSE_ENVELOPED hSignMsg,
cnProtected, "CounterSignature", perr);

return f;

errorReturn:
return false;
}
#endif

Expand Down Expand Up @@ -741,6 +749,11 @@ bool COSE_Recipient_CounterSign_validate(HCOSE_RECIPIENT hSignMsg,
HCOSE_COUNTERSIGN hCountersignature,
cose_errback* perr)
{
if (false) {
errorReturn:
return false;
}

CHECK_CONDITION(IsValidRecipientHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
IsValidCounterSignHandle(hCountersignature), COSE_ERR_INVALID_HANDLE);
Expand All @@ -762,9 +775,6 @@ bool COSE_Recipient_CounterSign_validate(HCOSE_RECIPIENT hSignMsg,
cnProtected, "CounterSignature", perr);

return f;

errorReturn:
return false;
}
#endif

Expand Down Expand Up @@ -811,6 +821,11 @@ bool COSE_Encrypt0_CounterSign_validate(HCOSE_ENCRYPT hSignMsg,
HCOSE_COUNTERSIGN hCountersignature,
cose_errback* perr)
{
if (false) {
errorReturn:
return false;
}

CHECK_CONDITION(IsValidEncryptHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
IsValidCounterSignHandle(hCountersignature), COSE_ERR_INVALID_HANDLE);
Expand All @@ -832,9 +847,6 @@ bool COSE_Encrypt0_CounterSign_validate(HCOSE_ENCRYPT hSignMsg,
cnProtected, "CounterSignature", perr);

return f;

errorReturn:
return false;
}
#endif

Expand Down Expand Up @@ -881,6 +893,11 @@ bool COSE_Mac0_CounterSign_validate(HCOSE_MAC0 hSignMsg,
HCOSE_COUNTERSIGN hCountersignature,
cose_errback* perr)
{
if (false) {
errorReturn:
return false;
}

CHECK_CONDITION(IsValidMac0Handle(hSignMsg), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
IsValidCounterSignHandle(hCountersignature), COSE_ERR_INVALID_HANDLE);
Expand All @@ -902,9 +919,6 @@ bool COSE_Mac0_CounterSign_validate(HCOSE_MAC0 hSignMsg,
cnProtected, "CounterSignature", perr);

return f;

errorReturn:
return false;
}
#endif

Expand Down Expand Up @@ -951,6 +965,11 @@ bool COSE_Mac_CounterSign_validate(HCOSE_MAC hSignMsg,
HCOSE_COUNTERSIGN hCountersignature,
cose_errback* perr)
{
if (false) {
errorReturn:
return false;
}

CHECK_CONDITION(IsValidMacHandle(hSignMsg), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(
IsValidCounterSignHandle(hCountersignature), COSE_ERR_INVALID_HANDLE);
Expand All @@ -972,9 +991,6 @@ bool COSE_Mac_CounterSign_validate(HCOSE_MAC hSignMsg,
cnProtected, "CounterSignature", perr);

return f;

errorReturn:
return false;
}
#endif

Expand Down
File renamed without changes.

0 comments on commit 11c78e8

Please sign in to comment.