-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
monero: only mask user features on new polyseed, not on decode #503
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,31 @@ fn valid_entropy(entropy: &Zeroizing<[u8; 32]>) -> bool { | |
res.into() | ||
} | ||
|
||
fn from_internal( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to have this outside the Polyseed impl? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because of the above 2 distinct call paths, I pulled out the Sort of similar line of thinking for the birthday btw ( |
||
language: Language, | ||
masked_features: u8, | ||
encoded_birthday: u16, | ||
entropy: Zeroizing<[u8; 32]>, | ||
) -> Result<Polyseed, SeedError> { | ||
if !polyseed_features_supported(masked_features) { | ||
Err(SeedError::UnsupportedFeatures)?; | ||
} | ||
|
||
if !valid_entropy(&entropy) { | ||
Err(SeedError::InvalidEntropy)?; | ||
} | ||
|
||
let mut res = Polyseed { | ||
language, | ||
birthday: encoded_birthday, | ||
features: masked_features, | ||
entropy, | ||
checksum: 0, | ||
}; | ||
res.checksum = poly_eval(&res.to_poly()); | ||
Ok(res) | ||
} | ||
|
||
impl Polyseed { | ||
// TODO: Clean this | ||
fn to_poly(&self) -> Poly { | ||
|
@@ -226,20 +251,7 @@ impl Polyseed { | |
birthday: u64, | ||
entropy: Zeroizing<[u8; 32]>, | ||
) -> Result<Polyseed, SeedError> { | ||
let features = user_features(features); | ||
if !polyseed_features_supported(features) { | ||
Err(SeedError::UnsupportedFeatures)?; | ||
} | ||
|
||
let birthday = birthday_encode(birthday); | ||
|
||
if !valid_entropy(&entropy) { | ||
Err(SeedError::InvalidEntropy)?; | ||
} | ||
|
||
let mut res = Polyseed { language, birthday, features, entropy, checksum: 0 }; | ||
res.checksum = poly_eval(&res.to_poly()); | ||
Ok(res) | ||
from_internal(language, user_features(features), birthday_encode(birthday), entropy) | ||
} | ||
|
||
/// Create a new `Polyseed`. | ||
|
@@ -375,9 +387,12 @@ impl Polyseed { | |
let features = | ||
u8::try_from(extra >> DATE_BITS).expect("couldn't convert extra >> DATE_BITS to u8"); | ||
|
||
let res = Polyseed::from(lang, features, birthday_decode(birthday), entropy); | ||
let res = from_internal(lang, features, birthday, entropy); | ||
if let Ok(res) = res.as_ref() { | ||
debug_assert_eq!(res.checksum, checksum); | ||
if res.checksum != checksum { | ||
// This should never trigger | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this should never trigger, the debug_assert is valid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, why should it be a debug assert and not a normal assert? I see no reason the function should return a normal response in a non-debug build if this statement is true. The seed would be invalid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess debug assert in one line, then return the invalid seed error in the next could make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it should be impossible, and is accordingly redundant, so it should be optimized out on release. |
||
Err(SeedError::InvalidSeed)?; | ||
} | ||
} | ||
res | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd clarify how it's invalid.