Skip to content
Snippets Groups Projects
Select Git revision
  • 61a1232e9dc34bf2fecf8b0db0151c829a9a3b28
  • master default protected
  • v1.23.2
  • v1.23.1
  • v1.23.0
  • v1.22.0
  • v1.21.1
  • v1.21.0
  • v1.20.3
  • v1.20.2
  • v1.20.1
  • v1.20.0
  • v1.19.4
  • v1.19.3
  • v1.19.2
  • v1.19.1
  • v1.19.0
  • v1.18.2
  • v1.18.1
  • v1.18.0
  • v1.17.0
  • v1.16.1
22 results

tables.go

Blame
  • tables.go 3.67 KiB
    // Copyright (c) 2019 The Go Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style
    // license that can be found in the LICENSE file.
    
    package edwards25519
    
    import (
    	"crypto/subtle"
    )
    
    // A dynamic lookup table for variable-base, constant-time scalar muls.
    type projLookupTable struct {
    	points [8]projCached
    }
    
    // A precomputed lookup table for fixed-base, constant-time scalar muls.
    type affineLookupTable struct {
    	points [8]affineCached
    }
    
    // A dynamic lookup table for variable-base, variable-time scalar muls.
    type nafLookupTable5 struct {
    	points [8]projCached
    }
    
    // A precomputed lookup table for fixed-base, variable-time scalar muls.
    type nafLookupTable8 struct {
    	points [64]affineCached
    }
    
    // Constructors.
    
    // Builds a lookup table at runtime. Fast.
    func (v *projLookupTable) FromP3(q *Point) {
    	// Goal: v.points[i] = (i+1)*Q, i.e., Q, 2Q, ..., 8Q
    	// This allows lookup of -8Q, ..., -Q, 0, Q, ..., 8Q
    	v.points[0].FromP3(q)
    	tmpP3 := Point{}
    	tmpP1xP1 := projP1xP1{}
    	for i := 0; i < 7; i++ {
    		// Compute (i+1)*Q as Q + i*Q and convert to a projCached
    		// This is needlessly complicated because the API has explicit
    		// receivers instead of creating stack objects and relying on RVO
    		v.points[i+1].FromP3(tmpP3.fromP1xP1(tmpP1xP1.Add(q, &v.points[i])))
    	}
    }
    
    // This is not optimised for speed; fixed-base tables should be precomputed.
    func (v *affineLookupTable) FromP3(q *Point) {
    	// Goal: v.points[i] = (i+1)*Q, i.e., Q, 2Q, ..., 8Q
    	// This allows lookup of -8Q, ..., -Q, 0, Q, ..., 8Q
    	v.points[0].FromP3(q)
    	tmpP3 := Point{}
    	tmpP1xP1 := projP1xP1{}
    	for i := 0; i < 7; i++ {
    		// Compute (i+1)*Q as Q + i*Q and convert to affineCached
    		v.points[i+1].FromP3(tmpP3.fromP1xP1(tmpP1xP1.AddAffine(q, &v.points[i])))
    	}
    }
    
    // Builds a lookup table at runtime. Fast.
    func (v *nafLookupTable5) FromP3(q *Point) {
    	// Goal: v.points[i] = (2*i+1)*Q, i.e., Q, 3Q, 5Q, ..., 15Q
    	// This allows lookup of -15Q, ..., -3Q, -Q, 0, Q, 3Q, ..., 15Q
    	v.points[0].FromP3(q)
    	q2 := Point{}
    	q2.Add(q, q)
    	tmpP3 := Point{}
    	tmpP1xP1 := projP1xP1{}
    	for i := 0; i < 7; i++ {