Skip to content

Commit

Permalink
fix(tfhe): remove unsafe integer parsing (ethereum#98)
Browse files Browse the repository at this point in the history
* fix(tfhe): remove unsafe integer parsing

* fix(tfhe): remove unused import
  • Loading branch information
tremblaythibaultl authored May 26, 2023
1 parent 93986eb commit d0af5bf
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions core/vm/tfhe.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ import "C"

import (
"crypto/rand"
"encoding/binary"
"errors"
"fmt"
"math/big"
Expand Down Expand Up @@ -545,19 +544,11 @@ func (ct *tfheCiphertext) encrypt(value big.Int, t fheUintType) {

switch t {
case FheUint8:
valBytes := [1]byte{}
value.FillBytes(valBytes[:])
ct.setPtr(C.client_key_encrypt_fhe_uint8(cks, C.uchar(valBytes[len(valBytes)-1])))
ct.setPtr(C.client_key_encrypt_fhe_uint8(cks, C.uchar(value.Uint64())))
case FheUint16:
valBytes := [2]byte{}
value.FillBytes(valBytes[:])
var valInt uint16 = binary.BigEndian.Uint16(valBytes[:])
ct.setPtr(C.client_key_encrypt_fhe_uint16(cks, C.ushort(valInt)))
ct.setPtr(C.client_key_encrypt_fhe_uint16(cks, C.ushort(value.Uint64())))
case FheUint32:
valBytes := [4]byte{}
value.FillBytes(valBytes[:])
var valInt uint32 = binary.BigEndian.Uint32(valBytes[:])
ct.setPtr(C.client_key_encrypt_fhe_uint32(cks, C.uint(valInt)))
ct.setPtr(C.client_key_encrypt_fhe_uint32(cks, C.uint(value.Uint64())))
}
ct.fheUintType = t
ct.value = &value
Expand Down

0 comments on commit d0af5bf

Please sign in to comment.