Header And Logo

| The world's most advanced open source database.

Defines | Functions

md5.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


#define MD5_PASSWD_LEN   35
#define isMD5(passwd)


bool pg_md5_hash (const void *buff, size_t len, char *hexsum)
bool pg_md5_binary (const void *buff, size_t len, void *outbuf)
bool pg_md5_encrypt (const char *passwd, const char *salt, size_t salt_len, char *buf)

Define Documentation

#define isMD5 (   passwd  ) 
(strncmp(passwd, "md5", 3) == 0 && \
                         strlen(passwd) == MD5_PASSWD_LEN)

Definition at line 21 of file md5.h.

Referenced by AlterRole(), CreateRole(), md5_crypt_verify(), and RenameRole().

#define MD5_PASSWD_LEN   35

Function Documentation

bool pg_md5_binary ( const void *  buff,
size_t  len,
void *  outbuf 

Definition at line 302 of file md5.c.

References calculateDigestFromBuffer().

Referenced by CheckRADIUSAuth().

    if (!calculateDigestFromBuffer(buff, len, outbuf))
        return false;
    return true;

bool pg_md5_encrypt ( const char *  passwd,
const char *  salt,
size_t  salt_len,
char *  buf 

Definition at line 320 of file md5.c.

References free, malloc, and pg_md5_hash().

Referenced by AlterRole(), check_password(), CreateRole(), md5_crypt_verify(), pg_password_sendauth(), and PQencryptPassword().

    size_t      passwd_len = strlen(passwd);

    /* +1 here is just to avoid risk of unportable malloc(0) */
    char       *crypt_buf = malloc(passwd_len + salt_len + 1);
    bool        ret;

    if (!crypt_buf)
        return false;

     * Place salt at the end because it may be known by users trying to crack
     * the MD5 output.
    memcpy(crypt_buf, passwd, passwd_len);
    memcpy(crypt_buf + passwd_len, salt, salt_len);

    strcpy(buf, "md5");
    ret = pg_md5_hash(crypt_buf, passwd_len + salt_len, buf + 3);


    return ret;

bool pg_md5_hash ( const void *  buff,
size_t  len,
char *  hexsum 

Definition at line 290 of file md5.c.

References bytesToHex(), and calculateDigestFromBuffer().

Referenced by md5_bytea(), md5_text(), and pg_md5_encrypt().

    uint8       sum[16];

    if (!calculateDigestFromBuffer(buff, len, sum))
        return false;

    bytesToHex(sum, hexsum);
    return true;