change Eval data structure to single code blob

This commit is contained in:
Scott Sadler
2018-04-07 18:07:52 -03:00
parent 4729632250
commit 39c9911e9c
37 changed files with 239 additions and 768 deletions

View File

@@ -22,3 +22,4 @@
converter-sample.c
config.*
.pytest_cache
src/asn/asn_system.h

View File

@@ -48,7 +48,6 @@ libcryptoconditions_core_la_SOURCES = \
src/asn/ThresholdFingerprintContents.c \
src/asn/RsaFingerprintContents.c \
src/asn/Ed25519FingerprintContents.c \
src/asn/EvalFingerprintContents.c \
src/asn/EvalFulfillment.c \
src/asn/Secp256k1FingerprintContents.c \
src/asn/Secp256k1Fulfillment.c \
@@ -83,3 +82,10 @@ test:
test-debug-interactive:
gdb -ex run --args python3 -m pytest -s -x -v
asn:
cd src/asn; \
mv asn_system.h asn_system.bak; \
rm *.c *.h; \
asn1c CryptoConditions.asn; \
mv asn_system.bak asn_system.h

View File

@@ -40,18 +40,18 @@ typedef struct CC {
struct CCType *type;
union {
// public key types
struct { unsigned char *publicKey, *signature; };
struct { uint8_t *publicKey, *signature; };
// preimage
struct { unsigned char *preimage; uint16_t preimageLength; };
struct { uint8_t *preimage; size_t preimageLength; };
// threshold
struct { long threshold; uint8_t size; struct CC **subconditions; };
// prefix
struct { unsigned char *prefix; uint16_t prefixLength; struct CC *subcondition;
uint16_t maxMessageLength; };
struct { uint8_t *prefix; size_t prefixLength; struct CC *subcondition;
size_t maxMessageLength; };
// eval
struct { char method[64]; unsigned char *paramsBin; uint16_t paramsBinLength; };
struct { uint8_t *code; size_t codeLength; };
// anon
struct { unsigned char fingerprint[32]; uint32_t subtypes; unsigned long cost;
struct { uint8_t fingerprint[32]; uint32_t subtypes; unsigned long cost;
struct CCType *conditionType; };
};
} CC;
@@ -63,7 +63,7 @@ typedef struct CC {
*/
typedef struct CCVisitor {
int (*visit)(CC *cond, struct CCVisitor visitor);
const unsigned char *msg;
const uint8_t *msg;
size_t msgLength;
void *context;
} CCVisitor;
@@ -73,20 +73,20 @@ typedef struct CCVisitor {
* Public methods
*/
int cc_isFulfilled(const CC *cond);
int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength,
int doHashMessage, const unsigned char *condBin, size_t condBinLength,
int cc_verify(const struct CC *cond, const uint8_t *msg, size_t msgLength,
int doHashMessage, const uint8_t *condBin, size_t condBinLength,
VerifyEval verifyEval, void *evalContext);
int cc_visit(CC *cond, struct CCVisitor visitor);
int cc_signTreeEd25519(CC *cond, const unsigned char *privateKey,
const unsigned char *msg, uint16_t msgLength);
int cc_signTreeSecp256k1Msg32(CC *cond, const unsigned char *privateKey, const unsigned char *msg32);
size_t cc_conditionBinary(const CC *cond, unsigned char *buf);
size_t cc_fulfillmentBinary(const CC *cond, unsigned char *buf, size_t bufLength);
static int cc_secp256k1VerifyTreeMsg32(const CC *cond, const unsigned char *msg32);
int cc_signTreeEd25519(CC *cond, const uint8_t *privateKey, const uint8_t *msg,
const size_t msgLength);
int cc_signTreeSecp256k1Msg32(CC *cond, const uint8_t *privateKey, const uint8_t *msg32);
int cc_secp256k1VerifyTreeMsg32(const CC *cond, const uint8_t *msg32);
size_t cc_conditionBinary(const CC *cond, uint8_t *buf);
size_t cc_fulfillmentBinary(const CC *cond, uint8_t *buf, size_t bufLength);
struct CC* cc_conditionFromJSON(cJSON *params, char *err);
struct CC* cc_conditionFromJSONString(const char *json, char *err);
struct CC* cc_readConditionBinary(const unsigned char *cond_bin, size_t cond_bin_len);
struct CC* cc_readFulfillmentBinary(const unsigned char *ffill_bin, size_t ffill_bin_len);
struct CC* cc_readConditionBinary(const uint8_t *cond_bin, size_t cond_bin_len);
struct CC* cc_readFulfillmentBinary(const uint8_t *ffill_bin, size_t ffill_bin_len);
struct CC* cc_new(int typeId);
struct cJSON* cc_conditionToJSON(const CC *cond);
char* cc_conditionToJSONString(const CC *cond);

View File

@@ -10,7 +10,7 @@
struct CCType CC_AnonType;
static CC *mkAnon(const Condition_t *asnCond) {
CC *mkAnon(const Condition_t *asnCond) {
CCType *realType = getTypeByAsnEnum(asnCond->present);
if (!realType) {

View File

@@ -1,94 +0,0 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* From ASN.1 module "Crypto-Conditions"
* found in "CryptoConditions.asn"
*/
#include "AuxFingerprintContents.h"
static int
memb_method_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
size_t size;
if(!sptr) {
ASN__CTFAIL(app_key, td, sptr,
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
size = st->size;
if((size == 64)) {
/* Constraint check succeeded */
return 0;
} else {
ASN__CTFAIL(app_key, td, sptr,
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
static asn_TYPE_member_t asn_MBR_AuxFingerprintContents_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct AuxFingerprintContents, method),
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
memb_method_constraint_1,
0, /* PER is not compiled, use -gen-PER */
0,
"method"
},
{ ATF_NOFLAGS, 0, offsetof(struct AuxFingerprintContents, conditionAux),
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"conditionAux"
},
};
static const ber_tlv_tag_t asn_DEF_AuxFingerprintContents_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_AuxFingerprintContents_tag2el_1[] = {
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* method */
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* conditionAux */
};
static asn_SEQUENCE_specifics_t asn_SPC_AuxFingerprintContents_specs_1 = {
sizeof(struct AuxFingerprintContents),
offsetof(struct AuxFingerprintContents, _asn_ctx),
asn_MAP_AuxFingerprintContents_tag2el_1,
2, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
};
asn_TYPE_descriptor_t asn_DEF_AuxFingerprintContents = {
"AuxFingerprintContents",
"AuxFingerprintContents",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
SEQUENCE_decode_xer,
SEQUENCE_encode_xer,
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
asn_DEF_AuxFingerprintContents_tags_1,
sizeof(asn_DEF_AuxFingerprintContents_tags_1)
/sizeof(asn_DEF_AuxFingerprintContents_tags_1[0]), /* 1 */
asn_DEF_AuxFingerprintContents_tags_1, /* Same as above */
sizeof(asn_DEF_AuxFingerprintContents_tags_1)
/sizeof(asn_DEF_AuxFingerprintContents_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
asn_MBR_AuxFingerprintContents_1,
2, /* Elements count */
&asn_SPC_AuxFingerprintContents_specs_1 /* Additional specs */
};

View File

@@ -1,38 +0,0 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* From ASN.1 module "Crypto-Conditions"
* found in "CryptoConditions.asn"
*/
#ifndef _AuxFingerprintContents_H_
#define _AuxFingerprintContents_H_
#include <asn_application.h>
/* Including external dependencies */
#include <OCTET_STRING.h>
#include <constr_SEQUENCE.h>
#ifdef __cplusplus
extern "C" {
#endif
/* AuxFingerprintContents */
typedef struct AuxFingerprintContents {
OCTET_STRING_t method;
OCTET_STRING_t conditionAux;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} AuxFingerprintContents_t;
/* Implementation */
extern asn_TYPE_descriptor_t asn_DEF_AuxFingerprintContents;
#ifdef __cplusplus
}
#endif
#endif /* _AuxFingerprintContents_H_ */
#include <asn_internal.h>

View File

@@ -1,78 +0,0 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* From ASN.1 module "Crypto-Conditions"
* found in "CryptoConditions.asn"
*/
#include "AuxFulfillment.h"
static asn_TYPE_member_t asn_MBR_AuxFulfillment_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct AuxFulfillment, method),
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"method"
},
{ ATF_NOFLAGS, 0, offsetof(struct AuxFulfillment, conditionAux),
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"conditionAux"
},
{ ATF_NOFLAGS, 0, offsetof(struct AuxFulfillment, fulfillmentAux),
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"fulfillmentAux"
},
};
static const ber_tlv_tag_t asn_DEF_AuxFulfillment_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_AuxFulfillment_tag2el_1[] = {
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* method */
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* conditionAux */
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* fulfillmentAux */
};
static asn_SEQUENCE_specifics_t asn_SPC_AuxFulfillment_specs_1 = {
sizeof(struct AuxFulfillment),
offsetof(struct AuxFulfillment, _asn_ctx),
asn_MAP_AuxFulfillment_tag2el_1,
3, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
};
asn_TYPE_descriptor_t asn_DEF_AuxFulfillment = {
"AuxFulfillment",
"AuxFulfillment",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
SEQUENCE_decode_xer,
SEQUENCE_encode_xer,
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
asn_DEF_AuxFulfillment_tags_1,
sizeof(asn_DEF_AuxFulfillment_tags_1)
/sizeof(asn_DEF_AuxFulfillment_tags_1[0]), /* 1 */
asn_DEF_AuxFulfillment_tags_1, /* Same as above */
sizeof(asn_DEF_AuxFulfillment_tags_1)
/sizeof(asn_DEF_AuxFulfillment_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
asn_MBR_AuxFulfillment_1,
3, /* Elements count */
&asn_SPC_AuxFulfillment_specs_1 /* Additional specs */
};

View File

@@ -1,39 +0,0 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* From ASN.1 module "Crypto-Conditions"
* found in "CryptoConditions.asn"
*/
#ifndef _AuxFulfillment_H_
#define _AuxFulfillment_H_
#include <asn_application.h>
/* Including external dependencies */
#include <OCTET_STRING.h>
#include <constr_SEQUENCE.h>
#ifdef __cplusplus
extern "C" {
#endif
/* AuxFulfillment */
typedef struct AuxFulfillment {
OCTET_STRING_t method;
OCTET_STRING_t conditionAux;
OCTET_STRING_t fulfillmentAux;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} AuxFulfillment_t;
/* Implementation */
extern asn_TYPE_descriptor_t asn_DEF_AuxFulfillment;
#ifdef __cplusplus
}
#endif
#endif /* _AuxFulfillment_H_ */
#include <asn_internal.h>

View File

@@ -1,78 +0,0 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* From ASN.1 module "Crypto-Conditions"
* found in "CryptoConditions.asn"
*/
#include "AuxSha512Fulfillment.h"
static asn_TYPE_member_t asn_MBR_AuxSha512Fulfillment_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct AuxSha512Fulfillment, method),
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"method"
},
{ ATF_NOFLAGS, 0, offsetof(struct AuxSha512Fulfillment, conditionAux),
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"conditionAux"
},
{ ATF_NOFLAGS, 0, offsetof(struct AuxSha512Fulfillment, fulfillmentAux),
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"fulfillmentAux"
},
};
static const ber_tlv_tag_t asn_DEF_AuxSha512Fulfillment_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_AuxSha512Fulfillment_tag2el_1[] = {
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* method */
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 }, /* conditionAux */
{ (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 2, 0, 0 } /* fulfillmentAux */
};
static asn_SEQUENCE_specifics_t asn_SPC_AuxSha512Fulfillment_specs_1 = {
sizeof(struct AuxSha512Fulfillment),
offsetof(struct AuxSha512Fulfillment, _asn_ctx),
asn_MAP_AuxSha512Fulfillment_tag2el_1,
3, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
};
asn_TYPE_descriptor_t asn_DEF_AuxSha512Fulfillment = {
"AuxSha512Fulfillment",
"AuxSha512Fulfillment",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
SEQUENCE_decode_xer,
SEQUENCE_encode_xer,
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
asn_DEF_AuxSha512Fulfillment_tags_1,
sizeof(asn_DEF_AuxSha512Fulfillment_tags_1)
/sizeof(asn_DEF_AuxSha512Fulfillment_tags_1[0]), /* 1 */
asn_DEF_AuxSha512Fulfillment_tags_1, /* Same as above */
sizeof(asn_DEF_AuxSha512Fulfillment_tags_1)
/sizeof(asn_DEF_AuxSha512Fulfillment_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
asn_MBR_AuxSha512Fulfillment_1,
3, /* Elements count */
&asn_SPC_AuxSha512Fulfillment_specs_1 /* Additional specs */
};

View File

@@ -1,39 +0,0 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* From ASN.1 module "Crypto-Conditions"
* found in "CryptoConditions.asn"
*/
#ifndef _AuxSha512Fulfillment_H_
#define _AuxSha512Fulfillment_H_
#include <asn_application.h>
/* Including external dependencies */
#include <OCTET_STRING.h>
#include <constr_SEQUENCE.h>
#ifdef __cplusplus
extern "C" {
#endif
/* AuxSha512Fulfillment */
typedef struct AuxSha512Fulfillment {
OCTET_STRING_t method;
OCTET_STRING_t conditionAux;
OCTET_STRING_t fulfillmentAux;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} AuxSha512Fulfillment_t;
/* Implementation */
extern asn_TYPE_descriptor_t asn_DEF_AuxSha512Fulfillment;
#ifdef __cplusplus
}
#endif
#endif /* _AuxSha512Fulfillment_H_ */
#include <asn_internal.h>

View File

@@ -78,14 +78,14 @@ Crypto-Conditions DEFINITIONS AUTOMATIC TAGS ::= BEGIN
}
EvalFulfillment ::= SEQUENCE {
method OCTET STRING (SIZE(64)),
paramsBin OCTET STRING
code OCTET STRING
}
-- Fingerprint Content
-- The PREIMAGE-SHA-256 condition fingerprint content is not DER encoded
-- The fingerprint content is the preimage
-- Same for Eval
PrefixFingerprintContents ::= SEQUENCE {
prefix OCTET STRING,
@@ -110,9 +110,4 @@ Crypto-Conditions DEFINITIONS AUTOMATIC TAGS ::= BEGIN
publicKey OCTET STRING (SIZE(33))
}
EvalFingerprintContents ::= SEQUENCE {
method OCTET STRING (SIZE(64)),
paramsBin OCTET STRING
}
END

View File

@@ -1,94 +0,0 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* From ASN.1 module "Crypto-Conditions"
* found in "CryptoConditions.asn"
*/
#include "EvalFingerprintContents.h"
static int
memb_method_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
size_t size;
if(!sptr) {
ASN__CTFAIL(app_key, td, sptr,
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
size = st->size;
if((size == 64)) {
/* Constraint check succeeded */
return 0;
} else {
ASN__CTFAIL(app_key, td, sptr,
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
static asn_TYPE_member_t asn_MBR_EvalFingerprintContents_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct EvalFingerprintContents, method),
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
memb_method_constraint_1,
0, /* PER is not compiled, use -gen-PER */
0,
"method"
},
{ ATF_NOFLAGS, 0, offsetof(struct EvalFingerprintContents, paramsBin),
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"paramsBin"
},
};
static const ber_tlv_tag_t asn_DEF_EvalFingerprintContents_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_EvalFingerprintContents_tag2el_1[] = {
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* method */
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* paramsBin */
};
static asn_SEQUENCE_specifics_t asn_SPC_EvalFingerprintContents_specs_1 = {
sizeof(struct EvalFingerprintContents),
offsetof(struct EvalFingerprintContents, _asn_ctx),
asn_MAP_EvalFingerprintContents_tag2el_1,
2, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
};
asn_TYPE_descriptor_t asn_DEF_EvalFingerprintContents = {
"EvalFingerprintContents",
"EvalFingerprintContents",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
SEQUENCE_decode_xer,
SEQUENCE_encode_xer,
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
asn_DEF_EvalFingerprintContents_tags_1,
sizeof(asn_DEF_EvalFingerprintContents_tags_1)
/sizeof(asn_DEF_EvalFingerprintContents_tags_1[0]), /* 1 */
asn_DEF_EvalFingerprintContents_tags_1, /* Same as above */
sizeof(asn_DEF_EvalFingerprintContents_tags_1)
/sizeof(asn_DEF_EvalFingerprintContents_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
asn_MBR_EvalFingerprintContents_1,
2, /* Elements count */
&asn_SPC_EvalFingerprintContents_specs_1 /* Additional specs */
};

View File

@@ -1,38 +0,0 @@
/*
* Generated by asn1c-0.9.28 (http://lionet.info/asn1c)
* From ASN.1 module "Crypto-Conditions"
* found in "CryptoConditions.asn"
*/
#ifndef _EvalFingerprintContents_H_
#define _EvalFingerprintContents_H_
#include <asn_application.h>
/* Including external dependencies */
#include <OCTET_STRING.h>
#include <constr_SEQUENCE.h>
#ifdef __cplusplus
extern "C" {
#endif
/* EvalFingerprintContents */
typedef struct EvalFingerprintContents {
OCTET_STRING_t method;
OCTET_STRING_t paramsBin;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} EvalFingerprintContents_t;
/* Implementation */
extern asn_TYPE_descriptor_t asn_DEF_EvalFingerprintContents;
#ifdef __cplusplus
}
#endif
#endif /* _EvalFingerprintContents_H_ */
#include <asn_internal.h>

View File

@@ -6,64 +6,28 @@
#include "EvalFulfillment.h"
static int
memb_method_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
size_t size;
if(!sptr) {
ASN__CTFAIL(app_key, td, sptr,
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
size = st->size;
if((size == 64)) {
/* Constraint check succeeded */
return 0;
} else {
ASN__CTFAIL(app_key, td, sptr,
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
static asn_TYPE_member_t asn_MBR_EvalFulfillment_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct EvalFulfillment, method),
{ ATF_NOFLAGS, 0, offsetof(struct EvalFulfillment, code),
(ASN_TAG_CLASS_CONTEXT | (0 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
memb_method_constraint_1,
0, /* PER is not compiled, use -gen-PER */
0,
"method"
},
{ ATF_NOFLAGS, 0, offsetof(struct EvalFulfillment, paramsBin),
(ASN_TAG_CLASS_CONTEXT | (1 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_OCTET_STRING,
0, /* Defer constraints checking to the member type */
0, /* PER is not compiled, use -gen-PER */
0,
"paramsBin"
"code"
},
};
static const ber_tlv_tag_t asn_DEF_EvalFulfillment_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_EvalFulfillment_tag2el_1[] = {
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 }, /* method */
{ (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 1, 0, 0 } /* paramsBin */
{ (ASN_TAG_CLASS_CONTEXT | (0 << 2)), 0, 0, 0 } /* code */
};
static asn_SEQUENCE_specifics_t asn_SPC_EvalFulfillment_specs_1 = {
sizeof(struct EvalFulfillment),
offsetof(struct EvalFulfillment, _asn_ctx),
asn_MAP_EvalFulfillment_tag2el_1,
2, /* Count of tags in the map */
1, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
@@ -88,7 +52,7 @@ asn_TYPE_descriptor_t asn_DEF_EvalFulfillment = {
/sizeof(asn_DEF_EvalFulfillment_tags_1[0]), /* 1 */
0, /* No PER visible constraints */
asn_MBR_EvalFulfillment_1,
2, /* Elements count */
1, /* Elements count */
&asn_SPC_EvalFulfillment_specs_1 /* Additional specs */
};

View File

@@ -20,8 +20,7 @@ extern "C" {
/* EvalFulfillment */
typedef struct EvalFulfillment {
OCTET_STRING_t method;
OCTET_STRING_t paramsBin;
OCTET_STRING_t code;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;

View File

@@ -15,8 +15,7 @@ ASN_MODULE_SOURCES= \
ThresholdFingerprintContents.c \
RsaFingerprintContents.c \
Ed25519FingerprintContents.c \
Secp256k1FingerprintContents.c \
EvalFingerprintContents.c
Secp256k1FingerprintContents.c
ASN_MODULE_HEADERS= \
Condition.h \
@@ -35,8 +34,7 @@ ASN_MODULE_HEADERS= \
ThresholdFingerprintContents.h \
RsaFingerprintContents.h \
Ed25519FingerprintContents.h \
Secp256k1FingerprintContents.h \
EvalFingerprintContents.h
Secp256k1FingerprintContents.h
ASN_MODULE_HEADERS+=INTEGER.h
ASN_MODULE_HEADERS+=NativeEnumerated.h

View File

@@ -125,14 +125,4 @@ typedef unsigned int uint32_t;
#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0))
#endif /* offsetof */
//#ifndef MIN /* Suitable for comparing primitive types (integers) */
//#if defined(__GNUC__)
//#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \
// ((_a)<(_b)?(_a):(_b)); })
//#else /* !__GNUC__ */
//#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */
//#endif /* __GNUC__ */
//#endif /* MIN */
#endif /* ASN_SYSTEM_H */

View File

@@ -69,7 +69,7 @@ char *cc_conditionUri(const CC *cond) {
}
static ConditionTypes_t asnSubtypes(uint32_t mask) {
ConditionTypes_t asnSubtypes(uint32_t mask) {
ConditionTypes_t types;
uint8_t buf[4] = {0,0,0,0};
int maxId = 0;
@@ -89,7 +89,7 @@ static ConditionTypes_t asnSubtypes(uint32_t mask) {
}
static uint32_t fromAsnSubtypes(const ConditionTypes_t types) {
uint32_t fromAsnSubtypes(const ConditionTypes_t types) {
uint32_t mask = 0;
for (int i=0; i<types.size*8; i++) {
if (types.buf[i >> 3] & (1 << (7 - i % 8))) {
@@ -125,7 +125,7 @@ size_t cc_fulfillmentBinary(const CC *cond, unsigned char *buf, size_t length) {
}
static void asnCondition(const CC *cond, Condition_t *asn) {
void asnCondition(const CC *cond, Condition_t *asn) {
asn->present = cc_isAnon(cond) ? cond->conditionType->asnType : cond->type->asnType;
// This may look a little weird - we dont have a reference here to the correct
@@ -140,14 +140,14 @@ static void asnCondition(const CC *cond, Condition_t *asn) {
}
static Condition_t *asnConditionNew(const CC *cond) {
Condition_t *asnConditionNew(const CC *cond) {
Condition_t *asn = calloc(1, sizeof(Condition_t));
asnCondition(cond, asn);
return asn;
}
static Fulfillment_t *asnFulfillmentNew(const CC *cond) {
Fulfillment_t *asnFulfillmentNew(const CC *cond) {
return cond->type->toFulfillment(cond);
}
@@ -167,7 +167,7 @@ CCType *getTypeByAsnEnum(Condition_PR present) {
}
static CC *fulfillmentToCC(Fulfillment_t *ffill) {
CC *fulfillmentToCC(Fulfillment_t *ffill) {
CCType *type = getTypeByAsnEnum(ffill->present);
if (!type) {
fprintf(stderr, "Unknown fulfillment type: %i\n", ffill->present);

View File

@@ -58,7 +58,8 @@ static int ed25519Sign(CC *cond, CCVisitor visitor) {
/*
* Sign ed25519 conditions in a tree
*/
int cc_signTreeEd25519(CC *cond, const unsigned char *privateKey, const unsigned char *msg, uint16_t msgLength) {
int cc_signTreeEd25519(CC *cond, const unsigned char *privateKey, const unsigned char *msg,
const size_t msgLength) {
unsigned char pk[32], skpk[64];
ed25519_create_keypair(pk, skpk, privateKey);
@@ -74,7 +75,7 @@ static unsigned long ed25519Cost(const CC *cond) {
}
static CC *ed25519FromJSON(const cJSON *params, unsigned char *err) {
static CC *ed25519FromJSON(const cJSON *params, char *err) {
size_t binsz;
cJSON *pk_item = cJSON_GetObjectItem(params, "publicKey");

View File

@@ -1,7 +1,6 @@
#include "asn/Condition.h"
#include "asn/Fulfillment.h"
#include "asn/EvalFulfillment.h"
#include "asn/EvalFingerprintContents.h"
#include "asn/OCTET_STRING.h"
#include "cryptoconditions.h"
#include "internal.h"
@@ -12,10 +11,9 @@ struct CCType CC_EvalType;
static unsigned char *evalFingerprint(const CC *cond) {
EvalFingerprintContents_t *fp = calloc(1, sizeof(EvalFingerprintContents_t));
OCTET_STRING_fromBuf(&fp->method, cond->method, strlen(cond->method));
OCTET_STRING_fromBuf(&fp->paramsBin, cond->paramsBin, cond->paramsBinLength);
return hashFingerprintContents(&asn_DEF_EvalFingerprintContents, fp);
unsigned char *hash = calloc(1, 32);
sha256(cond->code, cond->codeLength, hash);
return hash;
}
@@ -24,40 +22,26 @@ static unsigned long evalCost(const CC *cond) {
}
static CC *evalFromJSON(const cJSON *params, unsigned char *err) {
size_t paramsBinLength;
unsigned char *paramsBin = 0;
static CC *evalFromJSON(const cJSON *params, char *err) {
size_t codeLength;
unsigned char *code = 0;
cJSON *method_item = cJSON_GetObjectItem(params, "method");
if (!checkString(method_item, "method", err)) {
return NULL;
}
if (strlen(method_item->valuestring) > 64) {
strcpy(err, "method must be less than or equal to 64 bytes");
return NULL;
}
if (!jsonGetBase64(params, "params", err, &paramsBin, &paramsBinLength)) {
if (!jsonGetBase64(params, "code", err, &code, &codeLength)) {
return NULL;
}
CC *cond = cc_new(CC_Eval);
strcpy(cond->method, method_item->valuestring);
cond->paramsBin = paramsBin;
cond->paramsBinLength = paramsBinLength;
cond->code = code;
cond->codeLength = codeLength;
return cond;
}
static void evalToJSON(const CC *cond, cJSON *params) {
static void evalToJSON(const CC *cond, cJSON *code) {
// add method
cJSON_AddItemToObject(params, "method", cJSON_CreateString(cond->method));
// add params
unsigned char *b64 = base64_encode(cond->paramsBin, cond->paramsBinLength);
cJSON_AddItemToObject(params, "params", cJSON_CreateString(b64));
// add code
unsigned char *b64 = base64_encode(cond->code, cond->codeLength);
cJSON_AddItemToObject(code, "code", cJSON_CreateString(b64));
free(b64);
}
@@ -67,13 +51,10 @@ static CC *evalFromFulfillment(const Fulfillment_t *ffill) {
EvalFulfillment_t *eval = &ffill->choice.evalSha256;
memcpy(cond->method, eval->method.buf, eval->method.size);
cond->method[eval->method.size] = 0;
OCTET_STRING_t octets = eval->paramsBin;
cond->paramsBinLength = octets.size;
cond->paramsBin = malloc(octets.size);
memcpy(cond->paramsBin, octets.buf, octets.size);
OCTET_STRING_t octets = eval->code;
cond->codeLength = octets.size;
cond->code = malloc(octets.size);
memcpy(cond->code, octets.buf, octets.size);
return cond;
}
@@ -83,8 +64,7 @@ static Fulfillment_t *evalToFulfillment(const CC *cond) {
Fulfillment_t *ffill = calloc(1, sizeof(Fulfillment_t));
ffill->present = Fulfillment_PR_evalSha256;
EvalFulfillment_t *eval = &ffill->choice.evalSha256;
OCTET_STRING_fromBuf(&eval->method, cond->method, strlen(cond->method));
OCTET_STRING_fromBuf(&eval->paramsBin, cond->paramsBin, cond->paramsBinLength);
OCTET_STRING_fromBuf(&eval->code, cond->code, cond->codeLength);
return ffill;
}
@@ -95,7 +75,7 @@ int evalIsFulfilled(const CC *cond) {
static void evalFree(CC *cond) {
free(cond->paramsBin);
free(cond->code);
}
@@ -108,9 +88,8 @@ static uint32_t evalSubtypes(const CC *cond) {
* The JSON api doesn't contain custom verifiers, so a stub method is provided suitable for testing
*/
int jsonVerifyEval(CC *cond, void *context) {
if (strcmp(cond->method, "testEval") == 0) {
return memcmp(cond->paramsBin, "testEval", cond->paramsBinLength) == 0;
}
if (cond->codeLength == 9 && memcmp(cond->code, "TestEval", 8))
return cond->code[8];
fprintf(stderr, "Cannot verify eval; user function unknown\n");
return 0;
}

View File

@@ -39,21 +39,20 @@ typedef struct CCType {
/*
* Globals
*/
struct CCType *CCTypeRegistry[];
struct CCType *CCTypeRegistry[32];
int CCTypeRegistryLength;
/*
* Internal API
*/
static uint32_t fromAsnSubtypes(ConditionTypes_t types);
static CC *mkAnon(const Condition_t *asnCond);
static void asnCondition(const CC *cond, Condition_t *asn);
static Condition_t *asnConditionNew(const CC *cond);
static Fulfillment_t *asnFulfillmentNew(const CC *cond);
static cJSON *jsonEncodeCondition(cJSON *params, char *err);
static struct CC *fulfillmentToCC(Fulfillment_t *ffill);
static struct CCType *getTypeByAsnEnum(Condition_PR present);
uint32_t fromAsnSubtypes(ConditionTypes_t types);
CC *mkAnon(const Condition_t *asnCond);
void asnCondition(const CC *cond, Condition_t *asn);
Condition_t *asnConditionNew(const CC *cond);
Fulfillment_t *asnFulfillmentNew(const CC *cond);
struct CC *fulfillmentToCC(Fulfillment_t *ffill);
struct CCType *getTypeByAsnEnum(Condition_PR present);
/*

View File

@@ -74,7 +74,7 @@ static uint32_t prefixSubtypes(const CC *cond) {
}
static CC *prefixFromJSON(const cJSON *params, unsigned char *err) {
static CC *prefixFromJSON(const cJSON *params, char *err) {
cJSON *mml_item = cJSON_GetObjectItem(params, "maxMessageLength");
if (!cJSON_IsNumber(mml_item)) {
strcpy(err, "maxMessageLength must be a number");

View File

@@ -10,13 +10,13 @@
struct CCType CC_PreimageType;
static CC *preimageFromJSON(const cJSON *params, unsigned char *err) {
static CC *preimageFromJSON(const cJSON *params, char *err) {
cJSON *preimage_item = cJSON_GetObjectItem(params, "preimage");
if (!cJSON_IsString(preimage_item)) {
strcpy(err, "preimage must be a string");
return NULL;
}
unsigned char *preimage_b64 = preimage_item->valuestring;
char *preimage_b64 = preimage_item->valuestring;
CC *cond = cc_new(CC_Preimage);
cond->preimage = base64_decode(preimage_b64, &cond->preimageLength);

View File

@@ -97,7 +97,7 @@ int secp256k1Verify(CC *cond, CCVisitor visitor) {
}
static int cc_secp256k1VerifyTreeMsg32(const CC *cond, const unsigned char *msg32) {
int cc_secp256k1VerifyTreeMsg32(const CC *cond, const unsigned char *msg32) {
int subtypes = cc_typeMask(cond);
if (subtypes & (1 << CC_PrefixType.typeId) &&
subtypes & (1 << CC_Secp256k1Type.typeId)) {
@@ -209,7 +209,7 @@ static CC *cc_secp256k1Condition(const unsigned char *publicKey, const unsigned
}
static CC *secp256k1FromJSON(const cJSON *params, unsigned char *err) {
static CC *secp256k1FromJSON(const cJSON *params, char *err) {
CC *cond = 0;
unsigned char *pk = 0, *sig = 0;
size_t pkSize, sigSize;

View File

@@ -165,7 +165,7 @@ static Fulfillment_t *thresholdToFulfillment(const CC *cond) {
}
static CC *thresholdFromJSON(const cJSON *params, unsigned char *err) {
static CC *thresholdFromJSON(const cJSON *params, char *err) {
cJSON *threshold_item = cJSON_GetObjectItem(params, "threshold");
if (!cJSON_IsNumber(threshold_item)) {
strcpy(err, "threshold must be a number");

View File

@@ -1,7 +1,6 @@
{
"json": {
"type": "eval-sha-256",
"method": "testEval",
"params": "dGVzdEV2YWw"
},
"cost": 131072,