
Sodium Crypto Library의 Secretstream Xchacha20poly1305_push 함수에서 nonce를 생성하는 방법은 다음과 같습니다.
1. `crypto_secretstream_xchacha20poly1305_init_push` 함수를 호출하여 push 상태를 초기화합니다.
2. `crypto_secretstream_xchacha20poly1305_push` 함수를 호출하여 데이터를 암호화합니다.
3. `crypto_secretstream_xchacha20poly1305_push` 함수는 암호화된 데이터와 nonce를 반환합니다.
nonce는 매번 push 함수를 호출할 때마다 새로운 nonce를 생성해야 하므로, push 함수를 호출할 때마다 새로운 nonce를 생성해야 합니다.
nonce를 생성하는 방법은 다음과 같습니다.
- `crypto_secretstream_xchacha20poly1305_init_push` 함수를 호출하여 push 상태를 초기화합니다.
- `crypto_secretstream_xchacha20poly1305_push` 함수를 호출하여 nonce를 생성합니다.
nonce는 12바이트의 난수열입니다. Sodium Crypto Library에서는 `crypto_secretstream_xchacha20poly1305_push` 함수를 호출할 때마다 새로운 nonce를 생성합니다.
예를 들어, 다음과 같이 nonce를 생성하고 push 함수를 호출할 수 있습니다.
#hostingforum.kr
c
uint8_t key[32];
uint8_t nonce[12];
crypto_secretstream_xchacha20poly1305_init_push(key, &nonce, &state);
uint8_t data[] = "Hello, World!";
size_t data_len = strlen((char*)data);
uint8_t ciphertext[data_len + 16];
size_t ciphertext_len = crypto_secretstream_xchacha20poly1305_push(&state, data, data_len, ciphertext, &ciphertext_len);
이러한 방법으로 nonce를 생성하고 push 함수를 호출할 수 있습니다.
2025-07-04 16:12