Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nB9cq-0001bo-Ds for pgsql-general@arkaria.postgresql.org; Sat, 22 Jan 2022 06:11:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nB9co-000238-1T for pgsql-general@arkaria.postgresql.org; Sat, 22 Jan 2022 06:11:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nB9cn-00022z-NJ for pgsql-general@lists.postgresql.org; Sat, 22 Jan 2022 06:11:45 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nB9ch-0008IE-9y for pgsql-general@lists.postgresql.org; Sat, 22 Jan 2022 06:11:44 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4CDB05C018C; Sat, 22 Jan 2022 01:11:38 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sat, 22 Jan 2022 01:11:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; bh=CL3XmnEvaH6HSsFQvpTy33uPNisq6FE4h/kk0+ L9R7M=; b=MUhzDPzvx0b70v6C2uFkxaMeDlRqs+oPoJXv7wrxQczDnXOgAVY7nm W9xUKK/0Hi/gb97cWKaM8Ge+2HJ/akUjFBGvfB6qJph9kr/QEPHuSck6YRNOhzik 5Jd4YRFff2r/vGGCKDCPN7DQLUxcFRHFZ2q7/GWSantSbGXhZBrYAqJwnXge17Fn uZk9SYjMKTlYGoi++vHwIk2Ob6KbP80B2NXzW/W4Xl1g9pwgMimpGM+p4Yo4bEy8 WlkomECyzxDgAqz/TfLzlPhADQwszWBTePr2wWaSgfI2Xj97wrvP+eRLFbYATHOY NHunwOnsw940F8TKAWclcLaRZXEaKeTw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=CL3XmnEvaH6HSsFQv pTy33uPNisq6FE4h/kk0+L9R7M=; b=NoCaOpvMkwZDnLJ68lKRPapqxHN4fxyCA eJt80pSiC5zdIQxEgIkbcEIzii53uOd1VuGmR2uwgsWgACdS4Yj2OiEBIc+mUhy9 B4+sbbEqPeYYLoqJPCpEn1Ebtv5ha8rb2yhWfGl0Zq1324K4SScZNNMBQ8ZfFI3s tLJgh4GXA+Ewx4XvSxGaEoE0GD5Pa3iJpd47RqKpRw0UYnlCoX+i+d2C/mtbwPeC uMzp0LAmF77JPNm0Ddp/WuV5r/+F+D73oL46w9fF2Xv2IDMmdyIsDsXLu049m4OJ 7UCKr38xojX4BT0jvh1yJBtNQq+sJIVp7q1as52Y6rGgKE1eNZA0Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrvddugdeludcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddu necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepvedtgfekudduueevteefgefgjedu vddtteeuhfelueffueekiefhjefgieegudelnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 22 Jan 2022 01:11:36 -0500 (EST) Date: Sat, 22 Jan 2022 15:11:34 +0900 From: Michael Paquier To: Adrian Klaver Cc: Ali Koca , pgsql-general@lists.postgresql.org Subject: Re: How are md5.h: pg_md5_hash() function and below functions working? Message-ID: References: <533f71da-16f1-349e-d391-08f048ea27bc@aklaver.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5QjbotrtRD/i2ncW" Content-Disposition: inline In-Reply-To: <533f71da-16f1-349e-d391-08f048ea27bc@aklaver.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --5QjbotrtRD/i2ncW Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jan 08, 2022 at 08:12:50AM -0800, Adrian Klaver wrote: > On 1/8/22 05:21, Ali Koca wrote: >> I can't understand functions in md5.h, these are seemingly little bit >> weird. Such as: >> =A0=A0=A0=A0/* Utilities common to all the MD5 implementations, >> =A0=A0=A0=A0as of md5_common.c */ >> =A0=A0=A0=A0extern bool pg_md5_hash(const void *buff, size_t len, char = *hexsum); >> =A0=A0=A0=A0extern bool pg_md5_binary(const void *buff, size_t len, voi= d *outbuf); >> =A0=A0=A0=A0extern bool pg_md5_encrypt(const char *passwd, const char *= salt, >> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 size_t salt_len, char *buf); >=20 > What they do is explained in md5_common.c. pg_md5_hash() and pg_md5_binary() do the same thing, by computing a MD5. pg_md5_hash() computes it as a string in hex format, meaning that it is 33-character long with the final trailing '\0'. pg_md5_binary() computes 16 raw bytes. pg_md5_encrypt() is a utility wrapper that does the operation of pg_md5_hash() based on a password and a salt, used at authentication time for MD5. Its result is a 36-byte long string, prefixed with "md5" and a 33-byte long hex string. Those routine names are historic. -- Michael --5QjbotrtRD/i2ncW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmHroBYACgkQnvQgOdby QH39oQ/9Hq0cxOk4y5hbcVoeTu+poayxFgvU50c4Gmuef1HAp6qniCG1RCLrdjjH 6/M9THBjZNrMbaY0foec1QOaT3UUVj8k47WLq1LY+aDbZaXaldy533pi70v+EUSU TrwnroYE74zznrLhtDZr5/BaYL9/Kuqn/Y6nyiIqtUvT/11qGsJUk/qBtwahSGQw 3K/QoSUdFDSYnwizm6a7q61Xw/mDi0q6PRgQNlsl2xzcCcIOQsadyP8k2O8BcWbQ FTVR9f0Ar5cBH9R2sXbJlowDpPuObGKujGqHOUAHoMezW6m416fQ/gpqF/+5grrZ TUx7Lv6zFaajlR2MWopsTPAr8l5IrvXkE4pnVyPGmn0d+P7KIVLn575I6LoVL3iD khT5bW7rmZt0pDsrx78+Gppggyv61VnCwPJYPQJSXPmM1/i11SQZLIGcAaEB8suw l5RU/FJ0Bmqs49CDONqvvgvxfXVNgffQ0zkF6jnMUAwSa+E10jOWxvTxiDDn1vGL RKooqAJ74B67/dbdbvSgLsDAv3o6PNeRNthEvVprGKFJLx7sTSprBkPNz7j+qSSE Luf56ejAJ7y87M2z8mylRMQFbKDAYKVVR4St9D2TvpprSq44i5+du72iRuUlz1qU wZYBPAzu0LskDI8T3gKCdzAhjhJzxwYoxbagg5dkf/dTZCh++ss= =8Azx -----END PGP SIGNATURE----- --5QjbotrtRD/i2ncW--