// Copyright 2009 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.
// Package rc4 implements RC4 encryption, as defined in Bruce Schneier's// Applied Cryptography.//// RC4 is cryptographically broken and should not be used for secure// applications.
package rc4import ()// A Cipher is an instance of RC4 using a particular key.typeCipherstruct {s [256]uint32i, juint8}typeKeySizeErrorintfunc ( KeySizeError) () string {return"crypto/rc4: invalid key size " + strconv.Itoa(int())}// NewCipher creates and returns a new Cipher. The key argument should be the// RC4 key, at least 1 byte and at most 256 bytes.func ( []byte) (*Cipher, error) { := len()if < 1 || > 256 {returnnil, KeySizeError() }varCipherfor := 0; < 256; ++ { .s[] = uint32() }varuint8 = 0for := 0; < 256; ++ { += uint8(.s[]) + [%] .s[], .s[] = .s[], .s[] }return &, nil}// Reset zeros the key data and makes the Cipher unusable.//// Deprecated: Reset can't guarantee that the key will be entirely removed from// the process's memory.func ( *Cipher) () {for := range .s { .s[] = 0 } .i, .j = 0, 0}// XORKeyStream sets dst to the result of XORing src with the key stream.// Dst and src must overlap entirely or not at all.func ( *Cipher) (, []byte) {iflen() == 0 {return }ifalias.InexactOverlap([:len()], ) {panic("crypto/rc4: invalid buffer overlap") } , := .i, .j _ = [len()-1] = [:len()] // eliminate bounds check from loopfor , := range { += 1 := .s[] += uint8() := .s[] .s[], .s[] = , [] = ^ uint8(.s[uint8(+)]) } .i, .j = , }
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.