-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gosec - G115 #519
base: main
Are you sure you want to change the base?
Gosec - G115 #519
Conversation
panic(fmt.Errorf("invalid degree: cannot be negative")) | ||
} | ||
|
||
/* #nosec G115 -- degree cannot be negative */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add a check, gosec does not complain
/* #nosec G115 -- degree cannot be negative */ |
panic(fmt.Errorf("invalid degree: cannot be negative")) | ||
} | ||
|
||
/* #nosec G115 -- degree cannot be negative */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* #nosec G115 -- degree cannot be negative */ |
if n&(n-1) == 0 { | ||
a, b = n/2, n/2 //Necessary for optimal depth | ||
} else { | ||
// [Lee et al. 2020] : High-Precision and Low-Complexity Approximate Homomorphic Encryption by Error Variance Minimization | ||
// Maximize the number of odd terms of Chebyshev basis | ||
/* #nosec G115 -- n cannot be negative */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* #nosec G115 -- n cannot be negative */ | |
/* #nosec G115 -- n-1 cannot be negative */ |
@@ -107,6 +107,7 @@ func (op Element[T]) N() int { | |||
|
|||
// LogN returns the log2 of the ring degree used by the target element. | |||
func (op Element[T]) LogN() int { | |||
/* #nosec G115 -- N cannot be negative */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* #nosec G115 -- N cannot be negative */ | |
/* #nosec G115 -- N-1 cannot be negative */ |
@@ -231,13 +233,15 @@ func getGaloisElementInverseMap(GaloisGen uint64, N int) (GaloisGenDiscreteLog m | |||
|
|||
twoN := N << 1 | |||
NHalf := N >> 1 | |||
/* #nosec G115 -- twoN cannot be negative */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* #nosec G115 -- twoN cannot be negative */ | |
/* #nosec G115 -- twoN-1 cannot be negative */ |
@@ -67,6 +72,7 @@ func NewSubRingWithCustomNTT(N int, Modulus uint64, ntt func(*SubRing, int) Numb | |||
} | |||
|
|||
s.NTTTable = new(NTTTable) | |||
/* #nosec G115 -- NthRoot cannot be negative */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* #nosec G115 -- NthRoot cannot be negative */ |
/* #nosec G115 -- N cannot be negative */ | ||
logN := int(bits.Len64(uint64(N))) - 1 | ||
/* #nosec G115 -- M cannot be negative */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like the first "nosec" can be removed but not the second one as gosec doesn't understand M >= N => M >= 0
. It might be less confusing to keep both then.
@@ -52,7 +52,7 @@ func (m *Map[K, T]) WriteTo(w io.Writer) (n int64, err error) { | |||
|
|||
var inc int64 | |||
|
|||
if inc, err = buffer.WriteUint32(w, uint32(len(*m))); err != nil { | |||
if inc, err = buffer.WriteUint64(w, uint64(len(*m))); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if inc, err = buffer.WriteUint64(w, uint64(len(*m))); err != nil { | |
/* #nosec G115 -- marshalling support size of type uint32 only */ | |
if inc, err = buffer.WriteUint32(w, uint32(len(*m))); err != nil { |
I'd prefer to avoid breaking the serialization when not required.
var size uint64 | ||
if inc, err = buffer.ReadUint64(r, &size); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var size uint64 | |
if inc, err = buffer.ReadUint64(r, &size); err != nil { | |
var size uint32 | |
if inc, err = buffer.ReadUint32(r, &size); err != nil { |
@@ -141,7 +142,7 @@ func (m Map[K, T]) BinarySize() (size int) { | |||
panic(fmt.Errorf("vector component of type %T does not comply to %T", new(T), s)) | |||
} | |||
|
|||
size = 4 // #Ct | |||
size = 8 // #Ct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size = 8 // #Ct | |
size = 4 // #Ct |
# gosec rule G115: Is exluded because there are int->uin64 conversions | ||
# and the rule currently contains false positives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# gosec rule G115: Is exluded because there are int->uin64 conversions | |
# and the rule currently contains false positives |
structs.Map
fromu32
tou64
(who knows, maybe someone could try to marshal a map of 4 billions elements)