/** \file afs.h Exported symbols of the audio file selector. */
#include <regex.h>
-#include "hash.h"
/** Audio file selector data stored in the audio file table. */
struct afs_info {
char *path;
/** The score value (if -a was given). */
long score;
- /** The sha1 hash of audio file. */
- HASH_TYPE *hash;
+ /** The hash value of audio file data. */
+ unsigned char *hash;
};
/** Data about the current audio file, passed from afs to server. */
*/
static int aft_hash_compare(const struct osl_object *obj1, const struct osl_object *obj2)
{
- return hash_compare((HASH_TYPE *)obj1->data, (HASH_TYPE *)obj2->data);
+ return hash_compare((unsigned char *)obj1->data, (unsigned char *)obj2->data);
}
static struct osl_column_description aft_cols[] = {
*
* \return Standard.
*/
-static int aft_get_row_of_hash(HASH_TYPE *hash, struct osl_row **row)
+static int aft_get_row_of_hash(unsigned char *hash, struct osl_row **row)
{
const struct osl_object obj = {.data = hash, .size = HASH_SIZE};
return osl(osl_get_row(audio_file_table, AFTCOL_HASH, &obj, row));
* \return The return value of the underlying call to
* get_hash_object_of_aft_row().
*/
-static int get_hash_of_row(const struct osl_row *row, HASH_TYPE **hash)
+static int get_hash_of_row(const struct osl_row *row, unsigned char **hash)
{
struct osl_object obj;
int ret = get_hash_object_of_aft_row(row, &obj);
static int make_status_items(struct audio_file_data *afd,
struct afs_info *afsi, char *path, long score,
- HASH_TYPE *hash)
+ unsigned char *hash)
{
struct ls_data d = {
.afhi = afd->afhi,
int open_and_update_audio_file(struct osl_row *aft_row, long score,
struct audio_file_data *afd)
{
- HASH_TYPE *aft_hash, file_hash[HASH_SIZE];
+ unsigned char *aft_hash, file_hash[HASH_SIZE];
struct osl_object afsi_obj;
struct afs_info old_afsi, new_afsi;
int ret = get_hash_of_row(aft_row, &aft_hash);
func));
}
-static struct osl_row *find_hash_sister(HASH_TYPE *hash)
+static struct osl_row *find_hash_sister(unsigned char *hash)
{
const struct osl_object obj = {.data = hash, .size = HASH_SIZE};
struct osl_row *row;
* It's OK to call this with afhi == NULL. In this case, the audio format
* handler info won't be stored in the buffer.
*/
-static void save_add_callback_buffer(HASH_TYPE *hash, const char *path,
+static void save_add_callback_buffer(unsigned char *hash, const char *path,
struct afh_info *afhi, uint32_t flags,
uint8_t audio_format_num, struct osl_object *obj)
{
struct osl_row *pb, *aft_row;
struct osl_row *hs;
struct osl_object objs[NUM_AFT_COLUMNS];
- HASH_TYPE *hash;
+ unsigned char *hash;
char asc[2 * HASH_SIZE + 1];
int ret;
char afsi_buf[AFSI_SIZE];
.max_size_handler = pass_buffer_as_shm, .private_data = &fd};
uint16_t afhi_offset, chunks_offset;
- hash = (HASH_TYPE *)buf + CAB_HASH_OFFSET;
+ hash = (unsigned char *)buf + CAB_HASH_OFFSET;
hash_to_asc(hash, asc);;
objs[AFTCOL_HASH].data = buf + CAB_HASH_OFFSET;
objs[AFTCOL_HASH].size = HASH_SIZE;
objs[AFTCOL_CHUNKS].size = query->size - chunks_offset;
if (pb && !hs) { /* update pb's hash */
char old_asc[2 * HASH_SIZE + 1];
- HASH_TYPE *old_hash;
+ unsigned char *old_hash;
ret = get_hash_of_row(pb, &old_hash);
if (ret < 0)
goto out;
static void hash_sister_callback(int fd, const struct osl_object *query)
{
- HASH_TYPE *hash = query->data;
+ unsigned char *hash = query->data;
struct osl_row *hash_sister;
hash_sister = find_hash_sister(hash);
struct afh_info afhi, *afhi_ptr = NULL;
struct osl_row *pb = NULL, *hs = NULL; /* path brother/hash sister */
struct osl_object map, obj = {.data = NULL}, query;
- HASH_TYPE hash[HASH_SIZE];
+ unsigned char hash[HASH_SIZE];
ret = guess_audio_format(path);
if (ret < 0 && !(pad->flags & ADD_FLAG_ALL))
#include "string.h"
#include "client.cmdline.h"
#include "client.h"
-#include "hash.h"
#include "buffer_tree.h"
/** The size of the receiving buffer. */
/* decrypted challenge/session key buffer */
unsigned char crypt_buf[1024];
/* the SHA1 of the decrypted challenge */
- unsigned char challenge_sha1[HASH_SIZE];
+ unsigned char challenge_hash[HASH_SIZE];
ret = client_recv_buffer(ct, &s->rfds, buf, sizeof(buf), &n);
if (ret < 0 || n == 0)
(unsigned char *)buf, n);
if (ret < 0)
goto out;
- sha1_hash((char *)crypt_buf, CHALLENGE_SIZE, challenge_sha1);
+ hash_function((char *)crypt_buf, CHALLENGE_SIZE, challenge_hash);
ct->scc.send = sc_new(crypt_buf + CHALLENGE_SIZE, SESSION_KEY_LEN);
ct->scc.recv = sc_new(crypt_buf + CHALLENGE_SIZE + SESSION_KEY_LEN,
SESSION_KEY_LEN);
- hash_to_asc(challenge_sha1, buf);
+ hash_to_asc(challenge_hash, buf);
PARA_INFO_LOG("--> %s\n", buf);
- ret = send_bin_buffer(ct->scc.fd, (char *)challenge_sha1,
+ ret = send_bin_buffer(ct->scc.fd, (char *)challenge_hash,
HASH_SIZE);
if (ret < 0)
goto out;
int ret, argc;
char buf[4096];
unsigned char rand_buf[CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
- unsigned char challenge_sha1[HASH_SIZE];
+ unsigned char challenge_hash[HASH_SIZE];
struct user *u;
struct server_command *cmd = NULL;
char **argv = NULL;
if (!u)
goto net_err;
/*
- * The correct response is the sha1 of the first CHALLENGE_SIZE bytes
+ * The correct response is the hash of the first CHALLENGE_SIZE bytes
* of the random data.
*/
ret = -E_BAD_AUTH;
if (numbytes != HASH_SIZE)
goto net_err;
- sha1_hash((char *)rand_buf, CHALLENGE_SIZE, challenge_sha1);
- if (memcmp(challenge_sha1, buf, HASH_SIZE))
+ hash_function((char *)rand_buf, CHALLENGE_SIZE, challenge_hash);
+ if (memcmp(challenge_hash, buf, HASH_SIZE))
goto net_err;
/* auth successful */
alarm(0);
all_errlist_objs="server mp3_afh afh_common vss command net string signal time
daemon stat crypt http_send close_on_fork ipc acl afh fade amp_filter
dccp_send fd user_list chunk_queue afs aft mood score attribute blob ringbuffer
-playlist sha1 sched audiod grab_client filter_common wav_filter compress_filter
+playlist sched audiod grab_client filter_common wav_filter compress_filter
http_recv dccp_recv recv_common write_common file_write audiod_command
client_common recv stdout filter stdin audioc write client exec send_common ggo
udp_recv udp_send color fec fecdec_filter prebuffer_filter mm
audiod_errlist_objs="audiod signal string daemon stat net
time grab_client filter_common wav_filter compress_filter amp_filter http_recv dccp_recv
recv_common fd sched write_common file_write audiod_command crypt fecdec_filter
- client_common ggo udp_recv color fec prebuffer_filter sha1 audiod_command_list
+ client_common ggo udp_recv color fec prebuffer_filter audiod_command_list
bitstream imdct wma_common wmadec_filter buffer_tree"
audiod_ldflags="-lm"
audiod_audio_formats="wma"
server_errlist_objs="server afh_common mp3_afh vss command net string signal
time daemon crypt http_send close_on_fork mm
ipc dccp_send fd user_list chunk_queue afs aft mood score attribute
- blob playlist sha1 sched acl send_common udp_send color fec
+ blob playlist sched acl send_common udp_send color fec
server_command_list afs_command_list wma_afh wma_common"
server_ldflags=""
server_audio_formats="mp3 wma"
client_cmdline_objs="add_cmdline(client)"
client_errlist_objs="client net string crypt fd sched stdin stdout time
- client_common sha1 buffer_tree"
+ client_common buffer_tree"
client_ldflags=""
gui_cmdline_objs="add_cmdline(gui)"
#include <openssl/err.h>
#include <openssl/rc4.h>
#include <openssl/pem.h>
+#include <openssl/sha.h>
#include "para.h"
#include "error.h"
*buf = '\0';
return n;
}
+
+/**
+ * Compute the hash of the given input data.
+ *
+ * \param data Pointer to the data to compute the hash value from.
+ * \param len The length of \a data in bytes.
+ * \param hash Result pointer.
+ *
+ * \a hash must point to an area at least \p HASH_SIZE bytes large.
+ *
+ * \sa sha(3), openssl(1).
+ * */
+void hash_function(const char *data, unsigned long len, unsigned char *hash)
+{
+ SHA_CTX c;
+ SHA1_Init(&c);
+ SHA1_Update(&c, data, len);
+ SHA1_Final(hash, &c);
+}
#define LOAD_PRIVATE_KEY 1
#define CHALLENGE_SIZE 64
/** \endcond **/
+
+/** Size of the hash value in bytes. */
+#define HASH_SIZE 20
+
+void hash_function(const char *data, unsigned long len, unsigned char *hash);
+
+/**
+ * Compare two hashes.
+ *
+ * \param h1 Pointer to the first hash value.
+ * \param h2 Pointer to the second hash value.
+ *
+ * \return 1, -1, or zero, depending on whether \a h1 is greater than,
+ * less than or equal to h2, respectively.
+ */
+_static_inline_ int hash_compare(unsigned char *h1, unsigned char *h2)
+{
+ int i;
+
+ for (i = 0; i < HASH_SIZE; i++) {
+ if (h1[i] < h2[i])
+ return -1;
+ if (h1[i] > h2[i])
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * Convert a hash value to ascii format.
+ *
+ * \param hash the hash value.
+ * \param asc Result pointer.
+ *
+ * \a asc must point to an area of at least 2 * \p HASH_SIZE + 1 bytes which
+ * will be filled by the function with the ascii representation of the hash
+ * value given by \a hash, and a terminating \p NULL byte.
+ */
+_static_inline_ void hash_to_asc(unsigned char *hash, char *asc)
+{
+ int i;
+ const char hexchar[] = "0123456789abcdef";
+
+ for (i = 0; i < HASH_SIZE; i++) {
+ asc[2 * i] = hexchar[hash[i] >> 4];
+ asc[2 * i + 1] = hexchar[hash[i] & 0xf];
+ }
+ asc[2 * HASH_SIZE] = '\0';
+}
#define GUI_ERRORS
#define RINGBUFFER_ERRORS
#define SCORE_ERRORS
-#define SHA1_ERRORS
#define RBTREE_ERRORS
#define RECV_ERRORS
#define IPC_ERRORS
+++ /dev/null
-/*
- * Copyright (C) 2007-2011 Andre Noll <maan@systemlinux.org>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
-
-/** \file hash.h Inline functions for hash values. */
-
-/** hash arrays are always unsigned char. */
-#define HASH_TYPE unsigned char
-
-#include "sha1.h"
-/** We use openssl's sha1 implementation. */
-#define hash_function sha1_hash
-
-/**
- * Compare two hashes.
- *
- * \param h1 Pointer to the first hash value.
- * \param h2 Pointer to the second hash value.
- *
- * \return 1, -1, or zero, depending on whether \a h1 is greater than,
- * less than or equal to h2, respectively.
- */
-_static_inline_ int hash_compare(HASH_TYPE *h1, HASH_TYPE *h2)
-{
- int i;
-
- for (i = 0; i < HASH_SIZE; i++) {
- if (h1[i] < h2[i])
- return -1;
- if (h1[i] > h2[i])
- return 1;
- }
- return 0;
-}
-
-/**
- * Convert a hash value to ascii format.
- *
- * \param hash the hash value.
- * \param asc Result pointer.
- *
- * \a asc must point to an area of at least 2 * \p HASH_SIZE + 1 bytes which
- * will be filled by the function with the ascii representation of the hash
- * value given by \a hash, and a terminating \p NULL byte.
- */
-_static_inline_ void hash_to_asc(HASH_TYPE *hash, char *asc)
-{
- int i;
- const char hexchar[] = "0123456789abcdef";
-
- for (i = 0; i < HASH_SIZE; i++) {
- asc[2 * i] = hexchar[hash[i] >> 4];
- asc[2 * i + 1] = hexchar[hash[i] & 0xf];
- }
- asc[2 * HASH_SIZE] = '\0';
-}
*
* - Doubly linked lists: \ref list.h,
* - Ring buffer: \ref ringbuffer.c, \ref ringbuffer.h,
- * - Hashing: \ref hash.h, \ref sha1.h, \ref sha1.c,
- * - Crypto: \ref crypt.c.
+ * - Crypto: \ref crypt.c, \ref crypt.h.
* - Forward error correction: \ref fec.c.
*/
+++ /dev/null
-/*
- * Copyright (C) 2007-2011 Andre Noll <maan@systemlinux.org>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
-
-/** \file sha1.c Secure Hash Algorithm, provided by openssl. */
-
-#include "para.h"
-#include <openssl/sha.h>
-
-/**
- * Compute the sha1 hash.
- *
- * \param data Pointer to the data to compute the hash value from.
- * \param len The length of \a data in bytes.
- * \param sha1 Result pointer.
- *
- * \a sha1 must point to an area at least 20 bytes large.
- *
- * \sa sha(3), openssl(1).
- * */
-void sha1_hash(const char *data, unsigned long len, unsigned char *sha1)
-{
- SHA_CTX c;
- SHA1_Init(&c);
- SHA1_Update(&c, data, len);
- SHA1_Final(sha1, &c);
-}
+++ /dev/null
-/** \file sha1.h Secure Hash Algorithm prototype */
-
-/** Size of the hash value in bytes. */
-#define HASH_SIZE 20
-void sha1_hash(const char *data, unsigned long len, unsigned char *sha1);