Sylvain Munaut | f1d3344 | 2011-04-23 15:34:11 +0200 | [diff] [blame] | 1 | /* |
Sylvain Munaut | f1d3344 | 2011-04-23 15:34:11 +0200 | [diff] [blame] | 2 | * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com> |
| 3 | * |
| 4 | * All Rights Reserved |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 21 | #pragma once |
Sylvain Munaut | f1d3344 | 2011-04-23 15:34:11 +0200 | [diff] [blame] | 22 | |
| 23 | #include <stdint.h> |
| 24 | |
Max | fdb3d8c | 2016-04-21 16:51:04 +0200 | [diff] [blame] | 25 | #include <osmocom/core/defs.h> |
Sylvain Munaut | f1d3344 | 2011-04-23 15:34:11 +0200 | [diff] [blame] | 26 | #include <osmocom/core/bits.h> |
| 27 | |
Sylvain Munaut | 2735ac4 | 2011-11-17 21:01:46 +0100 | [diff] [blame] | 28 | /*! \defgroup a5 GSM A5 ciphering algorithm |
| 29 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 30 | * \file a5.h */ |
Sylvain Munaut | 2735ac4 | 2011-11-17 21:01:46 +0100 | [diff] [blame] | 31 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 32 | /*! Converts a frame number into the 22 bit number used in A5/x |
Sylvain Munaut | 2735ac4 | 2011-11-17 21:01:46 +0100 | [diff] [blame] | 33 | * \param[in] fn The true framenumber |
| 34 | * \return 22 bit word |
| 35 | */ |
Sylvain Munaut | f1d3344 | 2011-04-23 15:34:11 +0200 | [diff] [blame] | 36 | static inline uint32_t |
| 37 | osmo_a5_fn_count(uint32_t fn) |
| 38 | { |
| 39 | int t1 = fn / (26 * 51); |
| 40 | int t2 = fn % 26; |
| 41 | int t3 = fn % 51; |
| 42 | return (t1 << 11) | (t3 << 5) | t2; |
| 43 | } |
| 44 | |
| 45 | /* Notes: |
Max | f8699ca | 2015-03-25 17:20:31 +0100 | [diff] [blame] | 46 | * - key must be 8 or 16 (for a5/4) bytes long (or NULL for A5/0) |
Sylvain Munaut | f1d3344 | 2011-04-23 15:34:11 +0200 | [diff] [blame] | 47 | * - the dl and ul pointer must be either NULL or 114 bits long |
| 48 | * - fn is the _real_ GSM frame number. |
| 49 | * (converted internally to fn_count) |
| 50 | */ |
Sylvain Munaut | c1e9be9 | 2012-12-06 08:23:02 +0100 | [diff] [blame] | 51 | int osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); |
Max | fdb3d8c | 2016-04-21 16:51:04 +0200 | [diff] [blame] | 52 | void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) OSMO_DEPRECATED("Use generic osmo_a5() instead"); |
| 53 | void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) OSMO_DEPRECATED("Use generic osmo_a5() instead"); |
Sylvain Munaut | f1d3344 | 2011-04-23 15:34:11 +0200 | [diff] [blame] | 54 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 55 | /*! @} */ |