// mnemonicToCipherText converts a 24-word mnemonic phrase into a 33 byte
// cipher text.
//
// NOTE: This assumes that all words have already been checked to be amongst
// our word list.
19432
func mnemonicToCipherText(mnemonic *Mnemonic) [EncipheredCipherSeedSize]byte {
	var cipherText [EncipheredCipherSeedSize]byte

	// We'll now perform the reverse mapping to that of
	// cipherTextToMnemonic: we'll get the index of the word, then write
	// out that index to the bit stream.
	cipherBits := bstream.NewBStreamWriter(EncipheredCipherSeedSize)
	for _, word := range mnemonic {
		// Using the reverse word map, we'll locate the index of this
		// word within the word list.
		index := uint64(reverseWordMap[word])

		// With the index located, we'll now write this out to the
		// bitstream, appending to what's already there.
		cipherBits.WriteBits(index, bitsPerWord)
	}

	copy(cipherText[:], cipherBits.Bytes())

	return cipherText
}
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)
}
57843
func (c *cipher) key(key []byte) {
	var word uint
	off := 0
	lr := []uint{0, 0}
	plen := len(c.P)
	slen := len(c.S)

	for i := 0; i < plen; i++ {
		word, off = streamtoword(key, off)
		c.P[i] = c.P[i] ^ word
	}

	for i := 0; i < plen; i += 2 {
		c.encipher(lr, 0)
		c.P[i] = lr[0]
		c.P[i+1] = lr[1]
	}

	for i := 0; i < slen; i += 2 {
		c.encipher(lr, 0)
		c.S[i] = lr[0]
		c.S[i+1] = lr[1]
	}
}
723728
func (b *Board) MarshalText() (text []byte, err error) {
	return []byte(b.String()), nil
}
1341123
func (b *Sig) ToSignatureBytes() []byte {
	// Extract canonically-padded bigint representations from buffer
	r := extractCanonicalPadding(b[0:32])
	s := extractCanonicalPadding(b[32:64])
	rLen := uint8(len(r))
	sLen := uint8(len(s))

	// Create a canonical serialized signature. DER format is:
	// 0x30 <length> 0x02 <length r> r 0x02 <length s> s
	sigBytes := make([]byte, 6+rLen+sLen)
	sigBytes[0] = 0x30            // DER signature magic value
	sigBytes[1] = 4 + rLen + sLen // Length of rest of signature
	sigBytes[2] = 0x02            // Big integer magic value
	sigBytes[3] = rLen            // Length of R
	sigBytes[rLen+4] = 0x02       // Big integer magic value
	sigBytes[rLen+5] = sLen       // Length of S
	copy(sigBytes[4:], r)         // Copy R
	copy(sigBytes[rLen+6:], s)    // Copy S

	return sigBytes
}
11699
func (g *Game) MarshalText() (text []byte, err error) {
	return []byte(encodePGN(g)), nil
}
341393
func readCiphertext(filename string) ([]byte, int, *secret.SealedBytes, error) {
	plaintextBytes, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, 0, nil, err
	}

	var ec EncodedCiphertext
	err = json.Unmarshal(plaintextBytes, &ec)
	if err != nil {
		return nil, 0, nil, err
	}

	sealedBytes := &secret.SealedBytes{
		Ciphertext: ec.Ciphertext,
		Nonce:      ec.CiphertextNonce,
	}

	return ec.KeySalt, ec.KeyIter, sealedBytes, nil
}
763508
func (k *KMS) Encrypt(keyID, plaintext string) (string, error) {
	input := &kms.EncryptInput{
		KeyId:     &keyID,
		Plaintext: []byte(plaintext),
	}
	output, err := k.Client.Encrypt(input)
	if err != nil {
		return "", err
	}
	ciphertext, err := b64.Encode(output.CiphertextBlob)
	if err != nil {
		return "", err
	}
	return ciphertext, nil
}
1319229
func (k NaclSigningKeyPair) EncryptToString(plaintext []byte, sender GenericKey) (ciphertext string, err error) {
	err = KeyCannotEncryptError{}
	return
}
569489
func (c *ServerContext) DecryptMessage(msg []byte, seqno uint32) (uint32, []byte, error) {
	return decryptMessage(c.sctxt, msg, seqno)
}
218634
func phraseToInt(p Phrase, did DictionaryID) (*big.Int, error) {
	// Determine which dictionary to use based on the input language.
	var dict Dictionary
	var prefixLen int
	switch {
	case did == English:
		dict = englishDictionary
		prefixLen = EnglishUniquePrefixLen
	case did == German:
		dict = germanDictionary
		prefixLen = GermanUniquePrefixLen
	case did == Japanese:
		dict = japaneseDictionary
		prefixLen = JapaneseUniquePrefixLen
	default:
		return nil, errUnknownDictionary
	}

	base := big.NewInt(1626)
	exp := big.NewInt(1)
	result := big.NewInt(-1)
	for _, word := range p {
		// Normalize the input.
		word = norm.NFC.String(word)

		// Get the first prefixLen runes from the string.
		var prefix []byte
		var runeCount int
		for _, r := range word {
			encR := make([]byte, utf8.RuneLen(r))
			utf8.EncodeRune(encR, r)
			prefix = append(prefix, encR...)

			runeCount++
			if runeCount == prefixLen {
				break
			}
		}

		// Find the index associated with the phrase.
		var tmp *big.Int
		found := false
		for j, word := range dict {
			if strings.HasPrefix(word, string(prefix)) {
				tmp = big.NewInt(int64(j))
				found = true
				break
			}
		}
		if !found {
			return nil, errUnknownWord
		}

		// Add the index to the int.
		tmp.Add(tmp, big.NewInt(1))
		tmp.Mul(tmp, exp)
		exp.Mul(exp, base)
		result.Add(result, tmp)
	}
	return result, nil
}
253496
func ToKeywords(list []string) []Keyword {
	ret := make([]Keyword, len(list))
	for i := range list {
		ret[i] = Keyword(list[i])
	}
	return ret
}
976806
func GetCipherName(cipher uint16) (string, error) {
	for cipherStr, cipherCode := range cipherMap {
		if cipherCode == cipher {
			return cipherStr, nil
		}
	}
	return "", fmt.Errorf("unsupported cipher %d", cipher)
}
1028273
func (b Big) MarshalText() ([]byte, error) {
	return []byte(EncodeBig((*big.Int)(&b))), nil
}
292412
func NewCipher(key []byte) (cipher.Block, error) {
	if k := len(key); k != 16 && k != 24 && k != 32 {
		return nil, crypto.KeySizeError(k)
	}
	s := &subkeys{}
	s.keySchedule(key)
	return s, nil
}
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)
}
386714
func EncodeTLSInfoToText(tcs *tls.ConnectionState, cri *tls.CertificateRequestInfo) string {
	version := lookup(tlsVersions, tcs.Version)
	cipher := lookup(cipherSuites, tcs.CipherSuite)
	description := TLSDescription{
		Version: tlscolor(version),
		Cipher:  tlscolor(explainCipher(cipher)),
	}
	tlsInfoContext := tlsInfoContext{
		Conn: &description,
	}
	if cri != nil {
		criDesc, err := EncodeCRIToObject(cri)
		if err == nil {
			tlsInfoContext.CRI = criDesc.(*CertificateRequestInfo)
		}
	}

	funcMap := sprig.TxtFuncMap()
	extras := template.FuncMap{
		"printCommonName": PrintCommonName,
		"printShortName":  PrintShortName,
		"greenify":        greenify,
	}
	for k, v := range extras {
		funcMap[k] = v
	}

	t := template.New("TLS template").Funcs(funcMap)
	t, err := t.Parse(tlsLayout)
	if err != nil {
		// Should never happen
		panic(err)
	}
	var buffer bytes.Buffer
	w := bufio.NewWriter(&buffer)
	err = t.Execute(w, tlsInfoContext)
	if err != nil {
		// Should never happen
		panic(err)
	}
	w.Flush()
	return string(buffer.Bytes())
}