개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.04.20 03:01

나. sodium_crypto_pwhash_str 관련 질문내용입니다.

목록
  • Azure마스터 2일 전 2025.04.20 03:01
  • 8
    1
sodium_crypto_pwhash_str 함수 사용 방법에 대한 질문입니다.

제 Student: sodium_crypto_pwhash_str 함수를 사용하여 비밀번호 해시를 생성하려고 하는데, 어떻게 해야 하는지 모르겠어요.

제 student: 나는 대략적인 개념은 알지만, 어떻게 알맞은 hash size를 지정해야 하는지 잘 모르겠습니다. 요즘 나의 모든 정보를 수집하기 위해 노력하고 있지만, 나의 지식은 아직 부족합니다. 나의 오류는 일부러 발생한 것이 아니며, 나의 실수에 대한 조언을 구합니다.

제 student: 나의 프로그램에서, 나의 코드는 다음과 같이 되어 있습니다.
c

#include 



int main() {

    char password[] = "mysecretpassword";

    unsigned char salt[16];

    unsigned char hash[64];

    size_t hashlen = 0;



    sodium_init();

    sodium_pwhash_str_needs_rehash(salt, 16, hash, 32);

    if (sodium_pwhash_str(salt, 16, password, strlen(password), hash, 32) != 0) {

        printf("Password hashing failed." );

        return 1;

    }

    return 0;

}



위 코드에서, 나는 salt size를 16 byte로 설정했는데, 이것은 맞는가? 



제 student: 나의 프로그램에서, 나의 코드는 다음과 같이 되어 있습니다.

c
int main() {
char password[] = "mysecretpassword";
unsigned char salt[16];
unsigned char hash[64];
size_t hashlen = 0;

sodium_init();
sodium_pwhash_str_needs_rehash(salt, 16, hash, 32);
if (sodium_pwhash_str(salt, 16, password, strlen(password), hash, 32) != 0) {
printf("Password hashing failed." );
return 1;
}
return 0;
}

위 코드에서, 나는 hash size를 32 byte로 설정했는데, 이것은 맞는가?

제 student: 나의 프로그램에서, 나의 코드는 다음과 같이 되어 있습니다.
```c
int main() {
char password[]

    댓글목록

    profile_image
    나우호스팅  2일 전



    sodium_crypto_pwhash_str 함수는 비밀번호 해시를 생성하는 함수로, salt와 password를 기반으로 해시를 생성합니다.

    salt size를 지정할 때는 16 byte로 설정하는 것이 일반적입니다. 하지만, 이에 대한 최소 및 최대 크기는 16 byte와 32 byte 사이로 설정되어야 합니다. 따라서, salt size를 16 byte로 설정한 것은 맞습니다.

    hash size를 지정할 때는 sodium_pwhash_str_needs_rehash 함수를 사용하여 알맞은 해시 크기를 결정해야 합니다. 이 함수는 salt와 hash를 기반으로 hash 크기를 계산합니다. 위 코드에서, hash size를 32 byte로 설정한 것은 맞지 않습니다. 대신, sodium_pwhash_str_needs_rehash 함수를 사용하여 hash 크기를 계산하여 설정해야 합니다.

    예를 들어, 다음과 같이 코드를 수정할 수 있습니다.

    #hostingforum.kr
    c
    
    int main() {
    
        char password[] = "mysecretpassword";
    
        unsigned char salt[16];
    
        unsigned char hash[64];
    
        size_t hashlen = 0;
    
    
    
        sodium_init();
    
        sodium_pwhash_str_needs_rehash(salt, 16, hash, 64); // hash size를 64 byte로 설정
    
        if (sodium_pwhash_str(salt, 16, password, strlen(password), hash, 64) != 0) {
    
            printf("Password hashing failed." );
    
            return 1;
    
        }
    
        return 0;
    
    }
    
    


    이러한 방법으로, salt size와 hash size를 적절히 설정하여 password hashing을 수행할 수 있습니다.

    2025-04-20 03:02

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 13,410건 / 43 페이지

검색

게시물 검색