| 102 | */ |
| 103 | |
| 104 | static int authenticate (int fd, const char *pass) |
| 105 | { |
| 106 | char *challenge ; |
| 107 | char *encrypted ; |
| 108 | char salted [1024] ; |
| 109 | |
| 110 | if ((challenge = getChallenge (fd)) == NULL) |
| 111 | return -1 ; |
| 112 | |
| 113 | sprintf (salted, "$6$%s$", challenge) ; |
| 114 | encrypted = crypt (pass, salted) ; |
| 115 | |
| 116 | // This is an assertion, or sanity check on my part... |
| 117 | // The '20' comes from the $6$ then the 16 characters of the salt, |
| 118 | // then the terminating $. |
| 119 | |
| 120 | if (strncmp (encrypted, salted, 20) != 0) |
| 121 | { |
| 122 | errno = EBADE ; |
| 123 | return -1 ; |
| 124 | } |
| 125 | |
| 126 | // 86 characters is the length of the SHA-256 hash |
| 127 | |
| 128 | if (write (fd, encrypted + 20, 86) == 86) |
| 129 | return 0 ; |
| 130 | else |
| 131 | return -1 ; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /* |
no test coverage detected