Skip to content

Instantly share code, notes, and snippets.

@dtynn
Created July 22, 2020 12:05
Show Gist options
  • Save dtynn/1ad9e2761e4f6393d7990ea747108d6c to your computer and use it in GitHub Desktop.
Save dtynn/1ad9e2761e4f6393d7990ea747108d6c to your computer and use it in GitHub Desktop.
mul_256
pub fn mul_256(a: &[u64; 4], b: &[u64; 4]) -> [u64; 8] {
let mut carry = 0;
let r0 = mac_with_carry(0, a[0usize], b[0usize], &mut carry);
let r1 = mac_with_carry(0, a[0usize], b[1usize], &mut carry);
let r2 = mac_with_carry(0, a[0usize], b[2usize], &mut carry);
let r3 = mac_with_carry(0, a[0usize], b[3usize], &mut carry);
let r4 = carry;
let mut carry = 0;
let r1 = mac_with_carry(r1, a[1usize], b[0usize], &mut carry);
let r2 = mac_with_carry(r2, a[1usize], b[1usize], &mut carry);
let r3 = mac_with_carry(r3, a[1usize], b[2usize], &mut carry);
let r4 = mac_with_carry(r4, a[1usize], b[3usize], &mut carry);
let r5 = carry;
let mut carry = 0;
let r2 = mac_with_carry(r2, a[2usize], b[0usize], &mut carry);
let r3 = mac_with_carry(r3, a[2usize], b[1usize], &mut carry);
let r4 = mac_with_carry(r4, a[2usize], b[2usize], &mut carry);
let r5 = mac_with_carry(r5, a[2usize], b[3usize], &mut carry);
let r6 = carry;
let mut carry = 0;
let r3 = mac_with_carry(r3, a[3usize], b[0usize], &mut carry);
let r4 = mac_with_carry(r4, a[3usize], b[1usize], &mut carry);
let r5 = mac_with_carry(r5, a[3usize], b[2usize], &mut carry);
let r6 = mac_with_carry(r6, a[3usize], b[3usize], &mut carry);
let r7 = carry;
[r0, r1, r2, r3, r4, r5, r6, r7]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment