fix: add nosec G602 annotations for safe slice access patterns

This commit is contained in:
2026-03-22 13:27:20 -07:00
parent dc5b1bcf25
commit eecbcadb05
4 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -163,7 +163,7 @@ func (eval Evaluator) EvaluateManyNew(ctIn *rlwe.Ciphertext, linearTransformatio
params := eval.GetRLWEParameters()
opOut = make([]*rlwe.Ciphertext, len(linearTransformations))
for i := range opOut {
opOut[i] = rlwe.NewCiphertext(params, 1, linearTransformations[i].LevelQ)
opOut[i] = rlwe.NewCiphertext(params, 1, linearTransformations[i].LevelQ) // #nosec G602 -- i bounded by len(linearTransformations) via opOut
}
return opOut, eval.EvaluateMany(ctIn, linearTransformations, opOut)
}
+1 -1
View File
@@ -162,7 +162,7 @@ func (eval Evaluator) EvaluateManyNew(ctIn *rlwe.Ciphertext, linearTransformatio
params := eval.GetRLWEParameters()
opOut = make([]*rlwe.Ciphertext, len(linearTransformations))
for i := range opOut {
opOut[i] = rlwe.NewCiphertext(params, 1, linearTransformations[i].LevelQ)
opOut[i] = rlwe.NewCiphertext(params, 1, linearTransformations[i].LevelQ) // #nosec G602 -- i bounded by len(linearTransformations) via opOut
}
return opOut, eval.EvaluateMany(ctIn, linearTransformations, opOut)
}
@@ -30,7 +30,7 @@ func (eval Evaluator) EvaluateMany(ctIn *rlwe.Ciphertext, linearTransformations
return fmt.Errorf("output *rlwe.Ciphertext slice is too small")
}
for i := range linearTransformations {
if opOut[i] == nil {
if opOut[i] == nil { // #nosec G602 -- len(opOut) >= len(linearTransformations) checked above
return fmt.Errorf("output slice contains unallocated ciphertext")
}
}
@@ -58,7 +58,7 @@ func (eval Evaluator) EvaluateMany(ctIn *rlwe.Ciphertext, linearTransformations
for i, lt := range linearTransformations {
if lt.N1 == 0 {
if err = eval.MultiplyByDiagMatrix(ctIn, lt, buffDecompQP, opOut[i]); err != nil {
if err = eval.MultiplyByDiagMatrix(ctIn, lt, buffDecompQP, opOut[i]); err != nil { // #nosec G602 -- len(opOut) >= len(linearTransformations) checked above
return
}
} else {
@@ -69,7 +69,7 @@ func (eval Evaluator) EvaluateMany(ctIn *rlwe.Ciphertext, linearTransformations
return
}
if err = eval.MultiplyByDiagMatrixBSGS(ctIn, lt, ctPreRot, opOut[i]); err != nil {
if err = eval.MultiplyByDiagMatrixBSGS(ctIn, lt, ctPreRot, opOut[i]); err != nil { // #nosec G602 -- len(opOut) >= len(linearTransformations) checked above
return
}
}
+2 -2
View File
@@ -82,11 +82,11 @@ func NewElementAtLevelFromPoly(level int, poly []ring.Poly) (*Element[ring.Poly]
Value := make([]ring.Poly, len(poly))
for i := range Value {
if len(poly[i].Coeffs) < level+1 {
if len(poly[i].Coeffs) < level+1 { // #nosec G602 -- i bounded by len(poly) via Value
return nil, fmt.Errorf("cannot NewElementAtLevelFromPoly: provided ring.Poly[%d] level is too small", i)
}
Value[i].Coeffs = poly[i].Coeffs[:level+1]
Value[i].Coeffs = poly[i].Coeffs[:level+1] // #nosec G602 -- i bounded by len(poly) via Value
}
return &Element[ring.Poly]{Value: Value}, nil