Last active
June 23, 2024 03:45
-
-
Save bsidhom/8c3d8345073f7b7fc4d8e4bf21b8f891 to your computer and use it in GitHub Desktop.
Burn CPU cycles by running AES encryption in a loop. Useful for draining battery quickly and doing power tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/aes" | |
"crypto/cipher" | |
"crypto/rand" | |
"io" | |
"sync" | |
) | |
func main() { | |
var wg sync.WaitGroup | |
wg.Add(1) | |
for i := 0; i < 8; i++ { | |
go spin() | |
} | |
wg.Wait() | |
} | |
func spin() { | |
key := genKey() | |
blockCipher, err := aes.NewCipher(key) | |
if err != nil { | |
panic(err) | |
} | |
iv := genIv() | |
stream := cipher.NewCTR(blockCipher, iv) | |
buf := make([]byte, 16) | |
for { | |
for i := 0; i < 16; i++ { | |
buf[i] = 0 | |
} | |
stream.XORKeyStream(buf, buf) | |
} | |
} | |
func genKey() []byte { | |
key := make([]byte, 32) | |
_, err := io.ReadFull(rand.Reader, key) | |
if err != nil { | |
panic(err) | |
} | |
return key | |
} | |
func genIv() []byte { | |
iv := make([]byte, 16) | |
_, err := io.ReadFull(rand.Reader, iv) | |
if err != nil { | |
panic(err) | |
} | |
return iv | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment