1/* Copyright (c) 2018, Google Inc. 2 * 3 * Permission to use, copy, modify, and/or distribute this software for any 4 * purpose with or without fee is hereby granted, provided that the above 5 * copyright notice and this permission notice appear in all copies. 6 * 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 15package main 16 17import ( 18 "crypto/elliptic" 19 "fmt" 20 "math/big" 21) 22 23const numPoints = 64 24 25func printPadded(key string, n, max *big.Int) { 26 padded := make([]byte, len(max.Bytes())) 27 b := n.Bytes() 28 copy(padded[len(padded)-len(b):], b) 29 fmt.Printf("%s = %x\n", key, padded) 30} 31 32func printMultiples(name string, curve elliptic.Curve) { 33 n := new(big.Int) 34 for i := -numPoints; i <= numPoints; i++ { 35 fmt.Printf("Curve = %s\n", name) 36 n.SetInt64(int64(i)) 37 if i < 0 { 38 n = n.Add(n, curve.Params().N) 39 } 40 fmt.Printf("# N = %d\n", i) 41 printPadded("N", n, curve.Params().N) 42 x, y := curve.ScalarBaseMult(n.Bytes()) 43 printPadded("X", x, curve.Params().P) 44 printPadded("Y", y, curve.Params().P) 45 fmt.Printf("\n") 46 } 47} 48 49func main() { 50 fmt.Printf(`# This file contains multiples of the base point for various curves. The point 51# at infinity is represented as X = 0, Y = 0. 52# 53# This file is generated by make_ec_scalar_base_mult_tests.go 54 55`) 56 printMultiples("P-224", elliptic.P224()) 57 printMultiples("P-256", elliptic.P256()) 58 printMultiples("P-384", elliptic.P384()) 59 printMultiples("P-521", elliptic.P521()) 60} 61