Repo of no-std crates for my personal embedded projects

Sachy's crypto scheme lmao #13

open opened by sachy.dev targeting main from sachy-crypto
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:usjm3ynnir6y4inkcdovrfei/sh.tangled.repo.pull/3mhklndgukc22
+4 -14
Interdiff #4 #5
Cargo.lock

This file has not been changed.

Cargo.toml

This file has not been changed.

sachy-crypto/Cargo.toml

This file has not been changed.

+4 -14
sachy-crypto/src/lib.rs
··· 131 131 fn encrypt_in_place( 132 132 &self, 133 133 nonce: &aead::Nonce<A>, 134 - associated_data: &[u8], 135 134 buffer: &mut dyn Buffer, 136 135 ) -> Result<(), ProtoError>; 137 136 ··· 139 138 fn decrypt_in_place( 140 139 &self, 141 140 nonce: &aead::Nonce<A>, 142 - associated_data: &[u8], 143 141 buffer: &mut dyn Buffer, 144 142 ) -> Result<(), ProtoError>; 145 143 } ··· 169 167 } 170 168 171 169 pub fn encrypt(&mut self, msg: &mut alloc::vec::Vec<u8>) -> Result<(), ProtoError> { 172 - let counter = self.counter.to_le_bytes(); 173 - 174 170 let epstein = self.aead_nonce(self.counter); 175 171 176 - self.transport.encrypt_in_place(&epstein, &counter, msg)?; 172 + self.transport.encrypt_in_place(&epstein, msg)?; 177 173 178 174 msg.extend(epstein); 179 175 ··· 194 190 195 191 impl ReceivingState<'_> { 196 192 pub fn decrypt(&mut self, msg: &mut alloc::vec::Vec<u8>) -> Result<(), ProtoError> { 197 - let counter = self.counter.to_le_bytes(); 198 - 199 193 let index = msg.len() - <XChaCha20Poly1305 as AeadCore>::NonceSize::to_usize(); 200 194 201 195 // Extract the nonce from the payload as this does not need to be decrypted 202 196 let epstein = Array::try_from_iter(msg.drain(index..)).map_err(|_| ProtoError)?; 203 197 204 - self.transport.decrypt_in_place(&epstein, &counter, msg)?; 198 + self.transport.decrypt_in_place(&epstein, msg)?; 205 199 206 200 self.counter += TransportState::COUNTER_INCR; 207 201 ··· 225 219 fn encrypt_in_place( 226 220 &self, 227 221 epstein: &aead::Nonce<XChaCha20Poly1305>, 228 - associated_data: &[u8], 229 222 buffer: &mut dyn Buffer, 230 223 ) -> Result<(), ProtoError> { 231 - self.aead 232 - .encrypt_in_place(epstein, associated_data, buffer)?; 224 + self.aead.encrypt_in_place(epstein, epstein, buffer)?; 233 225 Ok(()) 234 226 } 235 227 236 228 fn decrypt_in_place( 237 229 &self, 238 230 epstein: &aead::Nonce<XChaCha20Poly1305>, 239 - associated_data: &[u8], 240 231 buffer: &mut dyn Buffer, 241 232 ) -> Result<(), ProtoError> { 242 - self.aead 243 - .decrypt_in_place(epstein, associated_data, buffer)?; 233 + self.aead.decrypt_in_place(epstein, epstein, buffer)?; 244 234 Ok(()) 245 235 } 246 236 }

History

8 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
no conflicts, ready to merge
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 failed
expand
expand 0 comments
sachy.dev submitted #5
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments
sachy.dev submitted #0
1 commit
expand
Sachy's crypto scheme lmao
2/2 success
expand
expand 0 comments