mikelodder7 / accumulator-rs

Cryptographic Accumulators in Rust
Apache License 2.0
64 stars 12 forks source link

Instantiate Accumulator with &[u8]? #3

Closed FrankC01 closed 3 years ago

FrankC01 commented 3 years ago

I receive, via 'wasm' a serialized array of bytes (big endian) representing a BigInteger value. E.g. [1u8, 0u8]

I am trying to create an Accumulator with that value as the starting state. I have this so far:

    pub fn accumulator_try_from(data: &mut &[u8]) -> Accumulator {
        // Infallible size
        fn read_be_usize(input: &mut &[u8]) -> usize {
            let (int_bytes, rest) = input.split_at(std::mem::size_of::<usize>());
            *input = rest;
            usize::from_be_bytes(int_bytes.try_into().unwrap())
        }
        let len = read_be_usize(data);        
        let (val, _rest) = data.split_at(len); // val = &[1u8, 0u8]          
        ;
     // NOT SURE BEST APPROACH HERE
 }

is this possible?

mikelodder7 commented 3 years ago

In rust you can use Accumulator::try_from(&data). It will fail if you just pass it two bytes as it expects as many bytes as the size of the modulus. I believe the minimum secure size is 256 bytes.

FrankC01 commented 3 years ago

So the only value I get via wasm is the value BigInteger.

The try_from expects 804 bytes as it assumes that the generator, value, modulus and member_count are part of the vector respectively.

mikelodder7 commented 3 years ago

I would add the generator and modulus to your data. Those are essential elements to the accumulator