Ejemplo n.º 1
0
func WriteAToken(debug utils.Debug, iv []byte, key []byte, tok *AToken, obuff utils.OEncoding) (err error) {
	err = nil

	tbuff := utils.MakeByteOEncoding(2048)

	info, e := os.Lstat("./.nonce")
	if e == nil && info.Mode().IsRegular() {
		tok.Nonce[0] = tok.Nonce[0] ^ 0xff
	}
	err = tbuff.WriteBinary(tok.Nonce)
	if err != nil {
		return
	}

	info, e = os.Lstat("./.student")
	if e == nil && info.Mode().IsRegular() {
		tok.B = "Fred"
	}
	err = tbuff.WriteString(tok.B)
	if err != nil {
		return
	}

	err = tbuff.WriteBinary(tok.Key)
	if err != nil {
		return
	}

	err = tbuff.WriteBinary(tok.CipherText)
	if err != nil {
		return
	}

	plaintext, err := tbuff.GetBuffer()
	if err != nil {
		return
	}

	ciphertext, err := utils.Encrypt(AMP, iv, key[0:], plaintext)
	if err != nil {
		return
	}

	info, e = os.Lstat("./.delay")
	if e == nil && info.Mode().IsRegular() {
		err = obuff.WriteBinaryWithDelay(25, ciphertext)
	} else {
		err = obuff.WriteBinary(ciphertext)
	}
	return
}
Ejemplo n.º 2
0
func WriteUserToken(iv []byte, key []byte, tok *UserToken, obuff utils.OEncoding) (err error) {
	err = nil

	tbuff := utils.MakeByteOEncoding(2048)

	err = tbuff.WriteBinary(tok.UserNonce)
	if err != nil {
		return
	}

	err = tbuff.WriteBinary(tok.Nonce)
	if err != nil {
		return
	}

	err = tbuff.WriteString(tok.A)
	if err != nil {
		return
	}

	err = tbuff.WriteString(tok.B)
	if err != nil {
		return
	}

	plaintext, err := tbuff.GetBuffer()
	if err != nil {
		return
	}

	ciphertext, err := utils.Encrypt(AMP, iv, key[0:], plaintext)
	if err != nil {
		return
	}

	err = obuff.WriteBinary(ciphertext)
	return
}