2 * @brief wrapper functions to allow easy use of MD5 from C++.
4 /* Copyright (C) 2006,2010,2012,2013,2015,2018 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "safeunistd.h"
35 md5_fd(int fd
, string
& md5
)
40 unsigned char blk
[4096];
43 int c
= read(fd
, blk
, sizeof(blk
));
46 if (errno
== EINTR
) continue;
49 MD5Update(&md5_ctx
, blk
, c
);
52 MD5Final(blk
, &md5_ctx
);
53 md5
.assign(reinterpret_cast<const char*>(blk
), 16);
59 md5_block(const char* p
, size_t len
, string
& md5
)
61 unsigned char blk
[16];
65 MD5Update(&md5_ctx
, reinterpret_cast<const unsigned char*>(p
), len
);
66 MD5Final(blk
, &md5_ctx
);
67 md5
.assign(reinterpret_cast<const char*>(blk
), 16);