OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [crypto/] [aes/] [cipher.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package aes
6
 
7
import "strconv"
8
 
9
// The AES block size in bytes.
10
const BlockSize = 16
11
 
12
// A Cipher is an instance of AES encryption using a particular key.
13
type Cipher struct {
14
        enc []uint32
15
        dec []uint32
16
}
17
 
18
type KeySizeError int
19
 
20
func (k KeySizeError) Error() string {
21
        return "crypto/aes: invalid key size " + strconv.Itoa(int(k))
22
}
23
 
24
// NewCipher creates and returns a new Cipher.
25
// The key argument should be the AES key,
26
// either 16, 24, or 32 bytes to select
27
// AES-128, AES-192, or AES-256.
28
func NewCipher(key []byte) (*Cipher, error) {
29
        k := len(key)
30
        switch k {
31
        default:
32
                return nil, KeySizeError(k)
33
        case 16, 24, 32:
34
                break
35
        }
36
 
37
        n := k + 28
38
        c := &Cipher{make([]uint32, n), make([]uint32, n)}
39
        expandKey(key, c.enc, c.dec)
40
        return c, nil
41
}
42
 
43
// BlockSize returns the AES block size, 16 bytes.
44
// It is necessary to satisfy the Block interface in the
45
// package "crypto/cipher".
46
func (c *Cipher) BlockSize() int { return BlockSize }
47
 
48
// Encrypt encrypts the 16-byte buffer src using the key k
49
// and stores the result in dst.
50
// Note that for amounts of data larger than a block,
51
// it is not safe to just call Encrypt on successive blocks;
52
// instead, use an encryption mode like CBC (see crypto/cipher/cbc.go).
53
func (c *Cipher) Encrypt(dst, src []byte) { encryptBlock(c.enc, dst, src) }
54
 
55
// Decrypt decrypts the 16-byte buffer src using the key k
56
// and stores the result in dst.
57
func (c *Cipher) Decrypt(dst, src []byte) { decryptBlock(c.dec, dst, src) }
58
 
59
// Reset zeros the key data, so that it will no longer
60
// appear in the process's memory.
61
func (c *Cipher) Reset() {
62
        for i := 0; i < len(c.enc); i++ {
63
                c.enc[i] = 0
64
        }
65
        for i := 0; i < len(c.dec); i++ {
66
                c.dec[i] = 0
67
        }
68
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.