aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-04-25 19:01:26 +0200
committerHarald Welte <laforge@gnumonks.org>2016-04-29 13:10:37 +0200
commit50f1c0af567423b6ade9a84aaa5197ecf6237819 (patch)
tree7f3ae0ca3ff35d790c29eac8b83f543feae0a59b /openbsc/src
parenteff215a8bb766e62a02bcc0f4334470a53475001 (diff)
move utils.h functions to libosmocore
This needs the corresponding commit in libosmocore which imports the related functions
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/gprs/oap.c4
-rw-r--r--openbsc/src/gprs/oap_messages.c9
-rw-r--r--openbsc/src/libcommon/Makefile.am2
-rw-r--r--openbsc/src/libcommon/utils.c58
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat.c3
5 files changed, 9 insertions, 67 deletions
diff --git a/openbsc/src/gprs/oap.c b/openbsc/src/gprs/oap.c
index 1426702dd..f5d7a9570 100644
--- a/openbsc/src/gprs/oap.c
+++ b/openbsc/src/gprs/oap.c
@@ -20,10 +20,10 @@
*
*/
+#include <osmocom/core/utils.h>
#include <osmocom/crypt/auth.h>
#include <openbsc/oap.h>
-#include <openbsc/utils.h>
#include <openbsc/debug.h>
#include <openbsc/oap_messages.h>
@@ -103,7 +103,7 @@ static int oap_evaluate_challenge(const struct oap_state *state,
return -3;
}
- if (constant_time_cmp(vec.autn, rx_autn, sizeof(vec.autn)) != 0) {
+ if (osmo_constant_time_cmp(vec.autn, rx_autn, sizeof(vec.autn)) != 0) {
LOGP(DGPRS, LOGL_ERROR, "OAP: AUTN mismatch!\n");
LOGP(DGPRS, LOGL_INFO, "OAP: AUTN from server: %s\n",
osmo_hexdump_nospc(rx_autn, sizeof(vec.autn)));
diff --git a/openbsc/src/gprs/oap_messages.c b/openbsc/src/gprs/oap_messages.c
index 49b54e439..d5750a612 100644
--- a/openbsc/src/gprs/oap_messages.c
+++ b/openbsc/src/gprs/oap_messages.c
@@ -20,11 +20,11 @@
*
*/
+#include <osmocom/core/utils.h>
#include <openbsc/oap_messages.h>
#include <openbsc/debug.h>
#include <openbsc/gprs_utils.h>
-#include <openbsc/utils.h>
#include <osmocom/gsm/tlv.h>
#include <osmocom/core/msgb.h>
@@ -51,7 +51,7 @@ int oap_decode(const uint8_t *const_data, size_t data_len,
rc = osmo_shift_v_fixed(&data, &data_len, 1, &value);
if (rc < 0)
return -GMM_CAUSE_INV_MAND_INFO;
- oap_msg->message_type = decode_big_endian(value, 1);
+ oap_msg->message_type = osmo_decode_big_endian(value, 1);
/* specific parts */
while (data_len > 0) {
@@ -72,7 +72,7 @@ int oap_decode(const uint8_t *const_data, size_t data_len,
return -GMM_CAUSE_PROTO_ERR_UNSPEC;
}
- oap_msg->client_id = decode_big_endian(value, value_len);
+ oap_msg->client_id = osmo_decode_big_endian(value, value_len);
if (oap_msg->client_id == 0) {
LOGP(DGPRS, LOGL_NOTICE,
@@ -159,7 +159,8 @@ void oap_encode(struct msgb *msg, const struct oap_message *oap_msg)
if (oap_msg->client_id > 0)
msgb_tlv_put(msg, OAP_CLIENT_ID_IE, sizeof(oap_msg->client_id),
- encode_big_endian(oap_msg->client_id, sizeof(oap_msg->client_id)));
+ osmo_encode_big_endian(oap_msg->client_id,
+ sizeof(oap_msg->client_id)));
if (oap_msg->rand_present)
msgb_tlv_put(msg, OAP_RAND_IE, sizeof(oap_msg->rand), oap_msg->rand);
diff --git a/openbsc/src/libcommon/Makefile.am b/openbsc/src/libcommon/Makefile.am
index 84c754452..75f40eea7 100644
--- a/openbsc/src/libcommon/Makefile.am
+++ b/openbsc/src/libcommon/Makefile.am
@@ -6,4 +6,4 @@ noinst_LIBRARIES = libcommon.a
libcommon_a_SOURCES = bsc_version.c common_vty.c debug.c gsm_data.c \
gsm_data_shared.c socket.c talloc_ctx.c \
- gsm_subscriber_base.c utils.c
+ gsm_subscriber_base.c
diff --git a/openbsc/src/libcommon/utils.c b/openbsc/src/libcommon/utils.c
deleted file mode 100644
index c47dcaee2..000000000
--- a/openbsc/src/libcommon/utils.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/* OpenBSC kitchen sink */
-
-/* (C) 2015 by sysmocom s.m.f.c GmbH <info@sysmocom.de>
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <openbsc/utils.h>
-#include <osmocom/core/utils.h>
-#include <osmocom/core/bit64gen.h>
-
-/* Wishful thinking to generate a constant time compare */
-int constant_time_cmp(const uint8_t *exp, const uint8_t *rel, const int count)
-{
- int x = 0, i;
-
- for (i = 0; i < count; ++i)
- x |= exp[i] ^ rel[i];
-
- /* if x is zero, all data was identical */
- return x? 1 : 0;
-}
-
-
-uint64_t decode_big_endian(const uint8_t *data, size_t data_len)
-{
- uint64_t value = 0;
-
- while (data_len > 0) {
- value = (value << 8) + *data;
- data += 1;
- data_len -= 1;
- }
-
- return value;
-}
-
-uint8_t *encode_big_endian(uint64_t value, size_t data_len)
-{
- static uint8_t buf[sizeof(uint64_t)];
- OSMO_ASSERT(data_len <= ARRAY_SIZE(buf));
- osmo_store64be_ext(value, buf, data_len);
- return buf;
-}
-
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c
index efae54f02..f20b2486f 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -48,7 +48,6 @@
#include <openbsc/abis_nm.h>
#include <openbsc/socket.h>
#include <openbsc/vty.h>
-#include <openbsc/utils.h>
#include <osmocom/ctrl/control_cmd.h>
#include <osmocom/ctrl/control_if.h>
@@ -1023,7 +1022,7 @@ static int verify_key(struct bsc_connection *conn, struct bsc_config *conf, cons
return 0;
}
- return constant_time_cmp(vec.res, key, 8) == 0;
+ return osmo_constant_time_cmp(vec.res, key, 8) == 0;
}
static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc)