@@ -2320,6 +2320,101 @@ func (points P1Affines) Mult(scalarsIf interface{}, nbits int) *P1 {
2320
2320
func (points P1s ) Mult (scalarsIf interface {}, nbits int ) * P1 {
2321
2321
return points .ToAffine ().Mult (scalarsIf , nbits )
2322
2322
}
2323
+
2324
+ //
2325
+ // Group-check
2326
+ //
2327
+
2328
+ func P1AffinesValidate (pointsIf interface {}) bool {
2329
+ var npoints int
2330
+ switch val := pointsIf .(type ) {
2331
+ case []* P1Affine :
2332
+ npoints = len (val )
2333
+ case []P1Affine :
2334
+ npoints = len (val )
2335
+ case P1Affines :
2336
+ npoints = len (val )
2337
+ default :
2338
+ panic (fmt .Sprintf ("unsupported type %T" , val ))
2339
+ }
2340
+
2341
+ numCores := runtime .GOMAXPROCS (0 )
2342
+ numThreads := maxProcs
2343
+ if numThreads > numCores {
2344
+ numThreads = numCores
2345
+ }
2346
+ if numThreads > npoints {
2347
+ numThreads = npoints
2348
+ }
2349
+
2350
+ if numThreads < 2 {
2351
+ for i := 0 ; i < npoints ; i ++ {
2352
+ var point * P1Affine
2353
+
2354
+ switch val := pointsIf .(type ) {
2355
+ case []* P1Affine :
2356
+ point = val [i ]
2357
+ case []P1Affine :
2358
+ point = & val [i ]
2359
+ case P1Affines :
2360
+ point = & val [i ]
2361
+ default :
2362
+ panic (fmt .Sprintf ("unsupported type %T" , val ))
2363
+ }
2364
+
2365
+ if ! C .go_p1_affine_validate (point , true ) {
2366
+ return false
2367
+ }
2368
+ }
2369
+
2370
+ return true
2371
+ }
2372
+
2373
+ valid := int32 (1 )
2374
+ curItem := uint32 (0 )
2375
+
2376
+ var wg sync.WaitGroup
2377
+ wg .Add (numThreads )
2378
+
2379
+ for tid := 0 ; tid < numThreads ; tid ++ {
2380
+ go func () {
2381
+ for atomic .LoadInt32 (& valid ) != 0 {
2382
+ work := atomic .AddUint32 (& curItem , 1 ) - 1
2383
+ if work >= uint32 (npoints ) {
2384
+ break
2385
+ }
2386
+
2387
+ var point * P1Affine
2388
+
2389
+ switch val := pointsIf .(type ) {
2390
+ case []* P1Affine :
2391
+ point = val [work ]
2392
+ case []P1Affine :
2393
+ point = & val [work ]
2394
+ case P1Affines :
2395
+ point = & val [work ]
2396
+ default :
2397
+ panic (fmt .Sprintf ("unsupported type %T" , val ))
2398
+ }
2399
+
2400
+ if ! C .go_p1_affine_validate (point , true ) {
2401
+ atomic .StoreInt32 (& valid , 0 )
2402
+ break
2403
+ }
2404
+ }
2405
+
2406
+ wg .Done ()
2407
+ }()
2408
+ }
2409
+
2410
+ wg .Wait ()
2411
+
2412
+ return atomic .LoadInt32 (& valid ) != 0
2413
+ }
2414
+
2415
+ func (points P1Affines ) Validate () bool {
2416
+ return P1AffinesValidate (points )
2417
+ }
2323
2418
func PairingAggregatePkInG2 (ctx Pairing , PK * P2Affine , pkValidate bool ,
2324
2419
sig * P1Affine , sigGroupcheck bool , msg []byte ,
2325
2420
optional ... []byte ) int { // aug
@@ -2983,6 +3078,101 @@ func (points P2s) Mult(scalarsIf interface{}, nbits int) *P2 {
2983
3078
return points .ToAffine ().Mult (scalarsIf , nbits )
2984
3079
}
2985
3080
3081
+ //
3082
+ // Group-check
3083
+ //
3084
+
3085
+ func P2AffinesValidate (pointsIf interface {}) bool {
3086
+ var npoints int
3087
+ switch val := pointsIf .(type ) {
3088
+ case []* P2Affine :
3089
+ npoints = len (val )
3090
+ case []P2Affine :
3091
+ npoints = len (val )
3092
+ case P2Affines :
3093
+ npoints = len (val )
3094
+ default :
3095
+ panic (fmt .Sprintf ("unsupported type %T" , val ))
3096
+ }
3097
+
3098
+ numCores := runtime .GOMAXPROCS (0 )
3099
+ numThreads := maxProcs
3100
+ if numThreads > numCores {
3101
+ numThreads = numCores
3102
+ }
3103
+ if numThreads > npoints {
3104
+ numThreads = npoints
3105
+ }
3106
+
3107
+ if numThreads < 2 {
3108
+ for i := 0 ; i < npoints ; i ++ {
3109
+ var point * P2Affine
3110
+
3111
+ switch val := pointsIf .(type ) {
3112
+ case []* P2Affine :
3113
+ point = val [i ]
3114
+ case []P2Affine :
3115
+ point = & val [i ]
3116
+ case P2Affines :
3117
+ point = & val [i ]
3118
+ default :
3119
+ panic (fmt .Sprintf ("unsupported type %T" , val ))
3120
+ }
3121
+
3122
+ if ! C .go_p2_affine_validate (point , true ) {
3123
+ return false
3124
+ }
3125
+ }
3126
+
3127
+ return true
3128
+ }
3129
+
3130
+ valid := int32 (1 )
3131
+ curItem := uint32 (0 )
3132
+
3133
+ var wg sync.WaitGroup
3134
+ wg .Add (numThreads )
3135
+
3136
+ for tid := 0 ; tid < numThreads ; tid ++ {
3137
+ go func () {
3138
+ for atomic .LoadInt32 (& valid ) != 0 {
3139
+ work := atomic .AddUint32 (& curItem , 1 ) - 1
3140
+ if work >= uint32 (npoints ) {
3141
+ break
3142
+ }
3143
+
3144
+ var point * P2Affine
3145
+
3146
+ switch val := pointsIf .(type ) {
3147
+ case []* P2Affine :
3148
+ point = val [work ]
3149
+ case []P2Affine :
3150
+ point = & val [work ]
3151
+ case P2Affines :
3152
+ point = & val [work ]
3153
+ default :
3154
+ panic (fmt .Sprintf ("unsupported type %T" , val ))
3155
+ }
3156
+
3157
+ if ! C .go_p2_affine_validate (point , true ) {
3158
+ atomic .StoreInt32 (& valid , 0 )
3159
+ break
3160
+ }
3161
+ }
3162
+
3163
+ wg .Done ()
3164
+ }()
3165
+ }
3166
+
3167
+ wg .Wait ()
3168
+
3169
+ return atomic .LoadInt32 (& valid ) != 0
3170
+ }
3171
+
3172
+ func (points P2Affines ) Validate () bool {
3173
+ return P2AffinesValidate (points )
3174
+ }
3175
+
2986
3176
func parseOpts (optional ... interface {}) ([]byte , [][]byte , bool , bool ) {
2987
3177
var aug [][]byte // For aggregate verify
2988
3178
var augSingle []byte // For signing
0 commit comments