PostgreSQL Source Code  git master
md5.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MD5_PASSWD_LEN   35
 

Functions

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)
 

Macro Definition Documentation

◆ MD5_PASSWD_LEN

Function Documentation

◆ pg_md5_binary()

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

Definition at line 305 of file md5.c.

References calculateDigestFromBuffer().

Referenced by PerformRadiusTransaction().

306 {
307  if (!calculateDigestFromBuffer(buff, len, outbuf))
308  return false;
309  return true;
310 }
static int calculateDigestFromBuffer(const uint8 *b, uint32 len, uint8 sum[16])
Definition: md5.c:188

◆ pg_md5_encrypt()

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

Definition at line 323 of file md5.c.

References free, malloc, and pg_md5_hash().

Referenced by encrypt_password(), md5_crypt_verify(), pg_password_sendauth(), plain_crypt_verify(), PQencryptPassword(), and PQencryptPasswordConn().

325 {
326  size_t passwd_len = strlen(passwd);
327 
328  /* +1 here is just to avoid risk of unportable malloc(0) */
329  char *crypt_buf = malloc(passwd_len + salt_len + 1);
330  bool ret;
331 
332  if (!crypt_buf)
333  return false;
334 
335  /*
336  * Place salt at the end because it may be known by users trying to crack
337  * the MD5 output.
338  */
339  memcpy(crypt_buf, passwd, passwd_len);
340  memcpy(crypt_buf + passwd_len, salt, salt_len);
341 
342  strcpy(buf, "md5");
343  ret = pg_md5_hash(crypt_buf, passwd_len + salt_len, buf + 3);
344 
345  free(crypt_buf);
346 
347  return ret;
348 }
#define malloc(a)
Definition: header.h:50
static char * buf
Definition: pg_test_fsync.c:67
#define free(a)
Definition: header.h:65
bool pg_md5_hash(const void *buff, size_t len, char *hexsum)
Definition: md5.c:293

◆ pg_md5_hash()

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

Definition at line 293 of file md5.c.

References bytesToHex(), and calculateDigestFromBuffer().

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

294 {
295  uint8 sum[16];
296 
297  if (!calculateDigestFromBuffer(buff, len, sum))
298  return false;
299 
300  bytesToHex(sum, hexsum);
301  return true;
302 }
unsigned char uint8
Definition: c.h:294
static int calculateDigestFromBuffer(const uint8 *b, uint32 len, uint8 sum[16])
Definition: md5.c:188
static void bytesToHex(uint8 b[16], char *s)
Definition: md5.c:248