-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a367af
commit f5b2a67
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod ed; | ||
pub mod sha; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use either::{Left, Right}; | ||
use crate::jets::util::slot; | ||
use crate::jets::{JetErr, Result}; | ||
use crate::mem::NockStack; | ||
use crate::newt::Newt; | ||
use crate::noun::{IndirectAtom, Noun}; | ||
use urcrypt_sys::*; | ||
|
||
crate::gdb!(); | ||
|
||
/* | ||
static u3_atom | ||
_cqee_puck(u3_atom sed) | ||
{ | ||
c3_y sed_y[32]; | ||
if ( 0 != u3r_bytes_fit(32, sed_y, sed) ) { | ||
// hoon explicitly crashes on mis-size | ||
return u3m_bail(c3__exit); | ||
} | ||
else { | ||
c3_y pub_y[32]; | ||
urcrypt_ed_puck(sed_y, pub_y); | ||
return u3i_bytes(32, pub_y); | ||
} | ||
} | ||
*/ | ||
|
||
pub fn jet_puck(stack: &mut NockStack, _newt: &mut Option<&mut Newt>, subject: Noun) -> Result { | ||
let sam = slot(subject, 6)?.as_direct()?; | ||
|
||
if sam.bit_size() > 32 { | ||
return Err(JetErr::Deterministic); // right? | ||
} | ||
|
||
unsafe { | ||
let (mut _seed_ida, seed) = IndirectAtom::new_raw_mut_bytes(stack, 32); | ||
let sam_bytes = sam.data().to_le_bytes(); | ||
// copy sam_bytes into seed one by one | ||
for i in 0..sam_bytes.len() { | ||
seed[i] = sam_bytes[i]; | ||
} | ||
|
||
let (mut pub_ida, pub_key) = IndirectAtom::new_raw_mut_bytes(stack, 32); | ||
urcrypt_ed_puck(seed.as_ptr(), pub_key.as_mut_ptr()); | ||
Ok(pub_ida.normalize_as_atom().as_noun()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use ibig::ubig; | ||
// use crate::noun::{D, T, DIRECT_MAX}; | ||
use crate::noun::D; | ||
use crate::jets::util::test::{A, assert_jet, init_stack, assert_jet_err, assert_jet_ubig}; | ||
// use crate::jets::JetErr; | ||
|
||
#[test] | ||
fn test_puck() { | ||
let s = &mut init_stack(); | ||
|
||
let ret = A(s, &ubig!(_0xfb099b0acc4d1ce37f9982a2ed331245e0cdfdf6979364b7676a142b8233e53b)); | ||
assert_jet(s, jet_puck, D(32), ret); | ||
} | ||
|
||
} |