Code RoomGCM message encryption
HardPrep Room Coding #2070

GCM message encryption

Code reviewSecurityDistributed systemsSenior–Staff~26 min

Review this Go message encryptor using AES-GCM with a counter nonce.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 26 min
Mark a line and say what kind of problem it is.0 findings
1var counter uint64
2 
3func Encrypt(key, plaintext []byte) ([]byte, error) {
4 block, _ := aes.NewCipher(key)
5 gcm, _ := cipher.NewGCM(block)
6 nonce := make([]byte, gcm.NonceSize())
7 binary.BigEndian.PutUint64(nonce[4:], counter)
8 counter++
9 return gcm.Seal(nil, nonce, plaintext, nil), nil
10}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.