Ejemplo n.º 1
0
// Determine all the alternative DH point positions for a ciphersuite.
func (si *suiteInfo) init(ste abstract.Suite, nlevels int) {
	si.ste = ste
	si.tag = make([]uint32, nlevels)
	si.pos = make([]int, nlevels)
	si.plen = ste.Point().(abstract.Hiding).HideLen() // XXX

	// Create a pseudo-random stream from which to pick positions
	str := fmt.Sprintf("NegoCipherSuite:%s", ste.String())
	rand := ste.Cipher([]byte(str))

	// Alternative 0 is always at position 0, so start with level 1.
	levofs := 0 // starting offset for current level
	//fmt.Printf("Suite %s positions:\n", ste.String())
	for i := 0; i < nlevels; i++ {

		// Pick a random position within this level
		var buf [4]byte
		rand.XORKeyStream(buf[:], buf[:])
		levlen := 1 << uint(i) // # alt positions at this level
		levmask := levlen - 1  // alternative index mask
		si.tag[i] = binary.BigEndian.Uint32(buf[:])
		levidx := int(si.tag[i]) & levmask
		si.pos[i] = levofs + levidx*si.plen

		//fmt.Printf("%d: idx %d/%d pos %d\n",
		//		i, levidx, levlen, si.pos[i])

		levofs += levlen * si.plen // next level table offset
	}

	// Limit of highest point field
	si.max = si.pos[nlevels-1] + si.plen
}
Ejemplo n.º 2
0
// Generate a new public/private keypair with the given ciphersuite
// and Save it to the application's previously-loaded configuration.
func (f *File) GenKey(keys *Keys, suite abstract.Suite) (KeyPair, error) {

	// Create the map if it doesn't exist
	//	if *keys == nil {
	//		*keys = make(map[string] KeyInfo)
	//	}

	// Create a fresh public/private keypair
	p := KeyPair{}
	p.Gen(suite, random.Stream)
	pubId := p.PubId()

	// Write the private key file
	secname := f.dirName + "/sec-" + pubId
	r := util.Replacer{}
	if err := r.Open(secname); err != nil {
		return KeyPair{}, err
	}
	defer r.Abort()

	// Write the secret key
	if err := suite.Write(r.File, &p.Secret); err != nil {
		return KeyPair{}, err
	}

	// Commit the secret key
	if err := r.Commit(); err != nil {
		return KeyPair{}, err
	}

	// Re-write the config file with the new public key
	*keys = append(*keys, KeyInfo{suite.String(), pubId})
	if err := f.Save(); err != nil {
		return KeyPair{}, err
	}

	return p, nil
}
Ejemplo n.º 3
0
func (s Suites) add(suite abstract.Suite) {
	s[suite.String()] = suite
}
Ejemplo n.º 4
0
package main

import (
	"os"

	"github.com/codegangsta/cli"
	"github.com/dedis/cothority/lib/cliutils"
	"github.com/dedis/cothority/lib/conode"
	"github.com/dedis/cothority/lib/dbg"
	"github.com/dedis/crypto/abstract"
	"github.com/dedis/crypto/edwards/ed25519"
)

// Which suite to use
var suite abstract.Suite = ed25519.NewAES128SHA256Ed25519(false)
var suiteStr string = suite.String()

// where to write the key file .priv + .pub
var defaultKeyFile string = "key"

// Returns the name of the file for the private key
func namePriv(key string) string {
	return key + ".priv"
}

// Returns the name of the file for the public key
func namePub(key string) string {
	return key + ".pub"
}

// config file by default