* Calculate ClientKey. Returns 0 on success, -1 on failure. */
| 114 | * Calculate ClientKey. Returns 0 on success, -1 on failure. |
| 115 | */ |
| 116 | int |
| 117 | scram_ClientKey(const uint8 *salted_password, uint8 *result) |
| 118 | { |
| 119 | pg_hmac_ctx *ctx = pg_hmac_create(PG_SHA256); |
| 120 | |
| 121 | if (ctx == NULL) |
| 122 | return -1; |
| 123 | |
| 124 | if (pg_hmac_init(ctx, salted_password, SCRAM_KEY_LEN) < 0 || |
| 125 | pg_hmac_update(ctx, (uint8 *) "Client Key", strlen("Client Key")) < 0 || |
| 126 | pg_hmac_final(ctx, result, SCRAM_KEY_LEN) < 0) |
| 127 | { |
| 128 | pg_hmac_free(ctx); |
| 129 | return -1; |
| 130 | } |
| 131 | |
| 132 | pg_hmac_free(ctx); |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Calculate ServerKey. Returns 0 on success, -1 on failure. |
no test coverage detected