// NewCipher creates and returns a new Block.
// The key argument should be the AES key,
// either 16, 24, or 32 bytes to select
// AES-128, AES-192, or AES-256.
965253
func NewCipher(key []byte) (Block, error) {
	k := len(key)
	switch k {
	default:
		return nil, KeySizeError(k)
	case 16, 24, 32:
		break
	}
	return newCipher(key)
}
929424
func Encrypt256(block *[4]uint64, keys *[5]uint64, tweak *[3]uint64) {
	b0, b1, b2, b3 := block[0], block[1], block[2], block[3]

	for r := 0; r < 17; r++ {
		b0 += keys[r%5]
		b1 += keys[(r+1)%5] + tweak[r%3]
		b2 += keys[(r+2)%5] + tweak[(r+1)%3]
		b3 += keys[(r+3)%5] + uint64(r)

		b0 += b1
		b1 = ((b1 << 14) | (b1 >> (64 - 14))) ^ b0
		b2 += b3
		b3 = ((b3 << 16) | (b3 >> (64 - 16))) ^ b2

		b0 += b3
		b3 = ((b3 << 52) | (b3 >> (64 - 52))) ^ b0
		b2 += b1
		b1 = ((b1 << 57) | (b1 >> (64 - 57))) ^ b2

		b0 += b1
		b1 = ((b1 << 23) | (b1 >> (64 - 23))) ^ b0
		b2 += b3
		b3 = ((b3 << 40) | (b3 >> (64 - 40))) ^ b2

		b0 += b3
		b3 = ((b3 << 5) | (b3 >> (64 - 5))) ^ b0
		b2 += b1
		b1 = ((b1 << 37) | (b1 >> (64 - 37))) ^ b2

		r++

		b0 += keys[r%5]
		b1 += keys[(r+1)%5] + tweak[r%3]
		b2 += keys[(r+2)%5] + tweak[(r+1)%3]
		b3 += keys[(r+3)%5] + uint64(r)

		b0 += b1
		b1 = ((b1 << 25) | (b1 >> (64 - 25))) ^ b0
		b2 += b3
		b3 = ((b3 << 33) | (b3 >> (64 - 33))) ^ b2

		b0 += b3
		b3 = ((b3 << 46) | (b3 >> (64 - 46))) ^ b0
		b2 += b1
		b1 = ((b1 << 12) | (b1 >> (64 - 12))) ^ b2

		b0 += b1
		b1 = ((b1 << 58) | (b1 >> (64 - 58))) ^ b0
		b2 += b3
		b3 = ((b3 << 22) | (b3 >> (64 - 22))) ^ b2

		b0 += b3
		b3 = ((b3 << 32) | (b3 >> (64 - 32))) ^ b0
		b2 += b1
		b1 = ((b1 << 32) | (b1 >> (64 - 32))) ^ b2
	}

	b0 += keys[3]
	b1 += keys[4] + tweak[0]
	b2 += keys[0] + tweak[1]
	b3 += keys[1] + uint64(18)

	block[0], block[1], block[2], block[3] = b0, b1, b2, b3
}
1277851
func newPacketCipher(d direction, algs directionAlgorithms, kex *kexResult) (packetCipher, error) {
	iv, key, macKey := generateKeys(d, algs, kex)

	if algs.Cipher == gcmCipherID {
		return newGCMCipher(iv, key, macKey)
	}

	c := &streamPacketCipher{
		mac: macModes[algs.MAC].new(macKey),
	}
	c.macResult = make([]byte, c.mac.Size())

	var err error
	c.cipher, err = cipherModes[algs.Cipher].createStream(key, iv)
	if err != nil {
		return nil, err
	}

	return c, nil
}
448555
func NewKey() Key {
	key := new([KeySize]byte)
	randombytes.MustRead(key[:])
	return key
}
1263751
func New(pw_cost uint, hmac_key []byte) (*ScryptAuth, error) {
	if pw_cost > 32 {
		return nil, errors.New("scryptauth new() - invalid pw_cost specified")
	}
	if len(hmac_key) != KEYLENGTH {
		return nil, errors.New("scryptauth new() - unsupported hmac_key length")
	}
	return &ScryptAuth{HmacKey: hmac_key, PwCost: pw_cost, R: SCRYPT_CONST_R, P: SCRYPT_CONST_P}, nil
}
217259
func New64(key []byte) (hash.Hash64, error) {
	if len(key) != Size {
		return nil, errKeySize
	}
	h := new(digest64)
	h.size = Size64
	copy(h.key[:], key)
	h.Reset()
	return h, nil
}
811379
func newBlockNode(blockHeader *wire.BlockHeader, parent *blockNode) *blockNode {
	var node blockNode
	initBlockNode(&node, blockHeader, parent)
	return &node
}
39445
func New(csp bccsp.BCCSP, key bccsp.Key) (crypto.Signer, error) {
	// Validate arguments
	if csp == nil {
		return nil, errors.New("bccsp instance must be different from nil.")
	}
	if key == nil {
		return nil, errors.New("key must be different from nil.")
	}
	if key.Symmetric() {
		return nil, errors.New("key must be asymmetric.")
	}

	// Marshall the bccsp public key as a crypto.PublicKey
	pub, err := key.PublicKey()
	if err != nil {
		return nil, errors.Wrap(err, "failed getting public key")
	}

	raw, err := pub.Bytes()
	if err != nil {
		return nil, errors.Wrap(err, "failed marshalling public key")
	}

	pk, err := utils.DERToPublicKey(raw)
	if err != nil {
		return nil, errors.Wrap(err, "failed marshalling der to public key")
	}

	return &bccspCryptoSigner{csp, key, pk}, nil
}
585981
func NewCrypter(key []byte) (e *Crypter, err error) {
	e = new(Crypter)

	if len(key) != sha512.Size256 {
		return nil, errors.Errorf("whatwhat: wrong key length. Got:%d", len(key))
	}

	e.key = key

	e.block, err = aes.NewCipher(e.key)
	if err != nil {
		return nil, errors.Wrap(err, "whatwhat: couldn't create AES cipher")
	}

	return e, nil
}
1251641
func newBlock(seqNum uint64, previousHash []byte) *common.Block {
	block := &common.Block{}
	block.Header = &common.BlockHeader{}
	block.Header.Number = seqNum
	block.Header.PreviousHash = previousHash
	block.Data = &common.BlockData{}

	var metadataContents [][]byte
	for i := 0; i < len(common.BlockMetadataIndex_name); i++ {
		metadataContents = append(metadataContents, []byte{})
	}
	block.Metadata = &common.BlockMetadata{Metadata: metadataContents}

	return block
}
1158417
func New(key *[16]byte) hash.Hash64 {
	h := new(hashFunc)
	h.key[0] = *(*uint64)(unsafe.Pointer(&key[0]))
	h.key[1] = *(*uint64)(unsafe.Pointer(&key[8]))
	h.Reset()
	return h
}
1297791
func NewCipher(key []byte) (cipher.Block, error) {
	k := len(key)
	if k == 16 {
		c := new(blockCipher128)
		c.keySchedule(key)
		return c, nil
	}
	if k == 24 || k == 32 {
		c := new(blockCipher256)
		c.keySchedule(key)
		return c, nil
	}
	return nil, crypto.KeySizeError(k)
}
836393
func NewXTEABlockCrypt(key []byte) (BlockCrypt, error) {
	c := new(xteaBlockCrypt)
	block, err := xtea.NewCipher(key)
	if err != nil {
		return nil, err
	}
	c.block = block
	return c, nil
}
317850
func newEncryptionKey(cmd *cobra.Command, client *http.Client) (ek encrypta.EncryptionKey, encryptSecret bool, err error) {
	if client == nil {
		client = http.DefaultClient
	}

	pgpKey := flagx.MustGetString(cmd, "pgp-key")
	pgpKeyURL := flagx.MustGetString(cmd, "pgp-key-url")
	keybaseUsername := flagx.MustGetString(cmd, "keybase")

	if pgpKey != "" {
		ek, err = encrypta.NewPublicKeyFromBase64Encoded(pgpKey)
		encryptSecret = true
		return
	}

	if pgpKeyURL != "" {
		ek, err = encrypta.NewPublicKeyFromURL(pgpKeyURL, encrypta.HTTPClientOption(client))
		encryptSecret = true
		return
	}

	if keybaseUsername != "" {
		ek, err = encrypta.NewPublicKeyFromKeybase(keybaseUsername, encrypta.HTTPClientOption(client))
		encryptSecret = true
		return
	}

	return nil, false, nil
}
1045389
func NewEncrypter(kp *Keypair, peerPublic [32]byte) *Encrypter {
	var shared [32]byte
	box.Precompute(&shared, &peerPublic, &kp.Private)
	return &Encrypter{
		Keypair:    kp,
		PeerPublic: peerPublic,
		SharedKey:  shared,
	}
}
136891
func NewKeychain(path string, password string) (Keychain, error) {
	return newKeychain(path, password, false)
}
366814
func (c *CipherSeed) Encipher(pass []byte) ([EncipheredCipherSeedSize]byte, error) {
	return c.encipher(pass)
}