tar: support -T - and -X -
[oweals/busybox.git] / libbb / pw_encrypt_des.c
index 4e506f4986cd2c39536f0dc4a7cb3a09e68093f2..c8e02ddff82f2424309f0f0b491c441c23e61ebd 100644 (file)
@@ -699,10 +699,16 @@ do_des(struct des_ctx *ctx, /*uint32_t l_in, uint32_t r_in,*/ uint32_t *l_out, u
 static void
 to64_msb_first(char *s, unsigned v)
 {
+#if 0
        *s++ = ascii64[(v >> 18) & 0x3f]; /* bits 23..18 */
        *s++ = ascii64[(v >> 12) & 0x3f]; /* bits 17..12 */
        *s++ = ascii64[(v >> 6) & 0x3f]; /* bits 11..6 */
-       *s = ascii64[v & 0x3f]; /* bits 5..0 */
+       *s   = ascii64[v & 0x3f]; /* bits 5..0 */
+#endif
+       *s++ = i64c(v >> 18); /* bits 23..18 */
+       *s++ = i64c(v >> 12); /* bits 17..12 */
+       *s++ = i64c(v >> 6); /* bits 11..6 */
+       *s   = i64c(v); /* bits 5..0 */
 }
 
 static char *
@@ -772,8 +778,10 @@ des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE],
        to64_msb_first(output + 2, (r0 >> 8));
        /* bits 7..0 of r0 and 31..16 of r1 */
        to64_msb_first(output + 6, (r0 << 16) | (r1 >> 16));
-       /* (bits 15..0 of r1 + 00) and NUL byte */
+       /* bits 15..0 of r1 and two zero bits (plus extra zero byte) */
        to64_msb_first(output + 10, (r1 << 8));
+       /* extra zero byte is encoded as '.', fixing it */
+       output[13] = '\0';
 #endif
 
        return output;