Skip to content

Commit 0b6e20a

Browse files
changed max_lwt_len to max_cred_len (#99)
* changed max_lwt_len to max_cred_len * Addressed doc FIXME
1 parent 82dfdd0 commit 0b6e20a

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed

circuit_setup/inputs/mdl1/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"credtype": "mdl",
33
"alg": "ES256",
4-
"max_jwt_len": 1152
4+
"max_cred_len": 1152
55
}

circuit_setup/scripts/crescent_helper.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
CIRCOM_RS256_LIMB_BITS = 121
1515
CIRCOM_ES256K_LIMB_BITS = 64
1616
CIRCOM_ES256_LIMB_BITS = 43 # Required by the ecdsa-p256 circuit we use
17-
CRESCENT_CONFIG_KEYS = ['alg', 'credtype', 'reveal_all_claims', 'defer_sig_ver', 'max_jwt_len'] # fields in config.json that are for crescent configuration and do not refer to claims in the token
17+
CRESCENT_CONFIG_KEYS = ['alg', 'credtype', 'reveal_all_claims', 'defer_sig_ver', 'max_cred_len'] # fields in config.json that are for crescent configuration and do not refer to claims in the token
1818
CRESCENT_SUPPORTED_ALGS = ['RS256', 'ES256', 'ES256K'] # Signature algorithms used to sign JWT/mDL
1919

2020

@@ -191,17 +191,17 @@ def check_config(config):
191191
if 'credtype' not in config:
192192
config['credtype'] = 'jwt'
193193

194-
if 'max_jwt_len' not in config:
195-
config['max_jwt_len'] = 2048 # Maximum length of JWT, excluding the
194+
if 'max_cred_len' not in config:
195+
config['max_cred_len'] = 2048 # Maximum length of JWT, excluding the
196196
# signature part. The length in bytes of the header
197197
# and payload, base64url encoded. Must be a multiple of 64.
198198
else:
199-
if type(config['max_jwt_len']) != int:
200-
print_debug("Error: config field 'max_jwt_len' must be an integer")
199+
if type(config['max_cred_len']) != int:
200+
print_debug("Error: config field 'max_cred_len' must be an integer")
201201
return False
202-
max_jwt_len = config['max_jwt_len']
203-
if max_jwt_len % 64 != 0:
204-
print_debug("Error: 'max_jwt_len' must be a multiple of 64. Found {}, try {}".format(max_jwt_len, (64 - (max_jwt_len % 64)) + max_jwt_len ))
202+
max_cred_len = config['max_cred_len']
203+
if max_cred_len % 64 != 0:
204+
print_debug("Error: 'max_cred_len' must be a multiple of 64. Found {}, try {}".format(max_cred_len, (64 - (max_cred_len % 64)) + max_cred_len ))
205205
return False
206206

207207
# Additional checks

circuit_setup/scripts/prepare_mdl_prover.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#!/usr/bin/python3
55

6-
import python_jwt as jwt, jwcrypto.jwk as jwk
76
from jwcrypto.common import base64url_encode
87
import sys, os
98
import json
@@ -162,7 +161,7 @@ def ymd_to_timestamp(ymd, is_bytes=False, has_time=False):
162161

163162
def ymd_to_daystamp(ymd, is_bytes=False, has_time=False):
164163
# Compute the number of days between Jan 1, year 0000 and input "YYYY-MM-DD"
165-
# The implementation of the Date class' toordinal() fucntion is here:
164+
# The implementation of the Date class' toordinal() function is here:
166165
# https://github.com/python/cpython/blob/54b5e4da8a4c6ae527ab238fcd6b9ba0a3ed0fc7/Lib/datetime.py#L63
167166
(year, month, day) = ymd.split("-")
168167
year = int(year)
@@ -211,12 +210,12 @@ def ymd_to_daystamp(ymd, is_bytes=False, has_time=False):
211210
msg_len_after_SHA2_padding = len(padded_m)
212211
print_debug("msg_len_after_SHA2_padding: {}".format(msg_len_after_SHA2_padding))
213212

214-
if msg_len_after_SHA2_padding > config['max_jwt_len']:
215-
print_debug("Error: JWT too large. Current token JSON header + payload is {} bytes ({} bytes after SHA256 padding), but maximum length supported is {} bytes.".format(len(tbs_data), msg_len_after_SHA2_padding, base64_decoded_size(config['max_jwt_len'])))
216-
print_debug("The config file value `max_jwt_len` would have to be increased to {} bytes (currently config['max_jwt_len'] = {})".format(len(tbs_data)+64, config['max_jwt_len']))
213+
if msg_len_after_SHA2_padding > config['max_cred_len']:
214+
print_debug("Error: mDL too large. Current mDL header + payload is {} bytes ({} bytes after SHA256 padding), but maximum length supported is {} bytes.".format(len(tbs_data), msg_len_after_SHA2_padding, base64_decoded_size(config['max_cred_len'])))
215+
print_debug("The config file value `max_cred_len` would have to be increased to {} bytes (currently config['max_cred_len'] = {})".format(len(tbs_data)+64, config['max_cred_len']))
217216
sys.exit(-1)
218217

219-
while (len(padded_m) < config['max_jwt_len']): # Additional zero padding for Circom program
218+
while (len(padded_m) < config['max_cred_len']): # Additional zero padding for Circom program
220219
padded_m = padded_m + [0]
221220

222221
sha256hash = hashlib.sha256(bytes(tbs_data))
@@ -269,7 +268,7 @@ def ymd_to_daystamp(ymd, is_bytes=False, has_time=False):
269268
exit(-1)
270269

271270
if config['alg'] == 'ES256':
272-
# See https://www.rfc-editor.org/rfc/rfc7515#appendix-A.3.1 for ECDSA encoding details in JWTs, the signature is R||S
271+
# See https://www.rfc-editor.org/rfc/rfc7515#appendix-A.3.1 for ECDSA encoding details, the signature is R||S
273272
# this code assumes |R|==|S|
274273
siglen = len(signature_bytes)
275274
assert(siglen % 2 == 0)

circuit_setup/scripts/prepare_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def prepare_circom(config, circom_output_file):
216216
main_input = "{ public [" + ", ".join(public_inputs) + " ] }"
217217
f.write('''
218218
component main {main_input} = Main({max_msg_len}, {max_json_len}, {max_field_byte_len}, {limb_size}, {n_limbs});
219-
'''.format(main_input = main_input, max_msg_len = config['max_jwt_len'], max_json_len = base64_decoded_size(config['max_jwt_len']), max_field_byte_len = MAX_FIELD_BYTE_LEN, limb_size=limb_size, n_limbs=n_limbs))
219+
'''.format(main_input = main_input, max_msg_len = config['max_cred_len'], max_json_len = base64_decoded_size(config['max_cred_len']), max_field_byte_len = MAX_FIELD_BYTE_LEN, limb_size=limb_size, n_limbs=n_limbs))
220220

221221

222222
print_debug("Claims:", claims)

creds/src/prep_inputs.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::utils::string_to_byte_vec;
1919
use crate::ProofSpec;
2020
use crate::ProofSpecInternal;
2121

22-
// If not set in config.json, the max_jwt_len is set to this value.
22+
// If not set in config.json, the max_cred_len is set to this value.
2323
const DEFAULT_MAX_TOKEN_LENGTH : usize = 2048;
2424
const CIRCOM_RS256_LIMB_BITS : usize = 121;
2525
const CIRCOM_ES256_LIMB_BITS : usize = 43; // Limb size required by ecdsa-p256 circuit
@@ -36,7 +36,7 @@ lazy_static! {
3636
let mut set = HashSet::new();
3737
set.insert("alg");
3838
set.insert("credtype");
39-
set.insert("max_jwt_len");
39+
set.insert("max_cred_len");
4040
set
4141
};
4242
}
@@ -127,19 +127,19 @@ Result<(JsonMap, JsonMap, JsonMap), Box<dyn Error>>
127127

128128
let msg_len_after_sha2_padding = padded_m.len() as u64;
129129

130-
if msg_len_after_sha2_padding > config["max_jwt_len"].as_u64().unwrap() {
131-
let errmsg = format!("Error: JWT too large. Current token JSON header + payload is {} bytes ({} bytes after SHA256 padding), but maximum length supported is {} bytes.\nThe config file value `max_jwt_len` would have to be increased to {} bytes (currently config['max_jwt_len'] = {})",
130+
if msg_len_after_sha2_padding > config["max_cred_len"].as_u64().unwrap() {
131+
let errmsg = format!("Error: JWT too large. Current token JSON header + payload is {} bytes ({} bytes after SHA256 padding), but maximum length supported is {} bytes.\nThe config file value `max_cred_len` would have to be increased to {} bytes (currently config['max_cred_len'] = {})",
132132
header_utf8.len() + payload_utf8.len(),
133133
msg_len_after_sha2_padding,
134-
base64_decoded_size(config["max_jwt_len"].as_u64().unwrap()),
135-
header_utf8.len() + payload_utf8.len() + 64, config["max_jwt_len"].as_u64().unwrap()
134+
base64_decoded_size(config["max_cred_len"].as_u64().unwrap()),
135+
header_utf8.len() + payload_utf8.len() + 64, config["max_cred_len"].as_u64().unwrap()
136136
);
137137

138138
return_error!(errmsg);
139139
}
140140

141141
// Add additional zero padding for Circom
142-
while padded_m.len() < config["max_jwt_len"].as_u64().unwrap() as usize {
142+
while padded_m.len() < config["max_cred_len"].as_u64().unwrap() as usize {
143143
padded_m.push(0);
144144
}
145145

@@ -517,18 +517,18 @@ pub fn parse_config(config_str: &str) -> Result<serde_json::Map<String, Value>,
517517
}
518518

519519
// Set defaults
520-
if !config.contains_key("max_jwt_len") {
521-
config.insert("max_jwt_len".to_string(), json!(DEFAULT_MAX_TOKEN_LENGTH));
520+
if !config.contains_key("max_cred_len") {
521+
config.insert("max_cred_len".to_string(), json!(DEFAULT_MAX_TOKEN_LENGTH));
522522
}
523523
else {
524-
if !config["max_jwt_len"].is_u64() {
525-
return_error!("max_jwt_len must have integer type");
524+
if !config["max_cred_len"].is_u64() {
525+
return_error!("max_cred_len must have integer type");
526526
}
527-
let max_jwt_len = config["max_jwt_len"].as_u64().ok_or("Invalid value for max_jwt_len")?;
528-
if max_jwt_len % 64 != 0 {
529-
let round = (64 - (max_jwt_len % 64)) + max_jwt_len;
530-
config["max_jwt_len"] = json!(round);
531-
println!("Warning: max_jwt_len not a multiple of 64. Rounded from {} to {}", max_jwt_len, round);
527+
let max_cred_len = config["max_cred_len"].as_u64().ok_or("Invalid value for max_cred_len")?;
528+
if max_cred_len % 64 != 0 {
529+
let round = (64 - (max_cred_len % 64)) + max_cred_len;
530+
config["max_cred_len"] = json!(round);
531+
println!("Warning: max_cred_len not a multiple of 64. Rounded from {} to {}", max_cred_len, round);
532532
}
533533
}
534534

0 commit comments

Comments
 (0)