net80211_crypto_ccmp.c revision e2cf88ac9d753a00c17aa235f6afdc76574fe3a6
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2001 Atsushi Onoe
* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* IEEE 802.11i CCMP crypto support.
*/
#include <sys/byteorder.h>
#include "net80211_impl.h"
struct ccmp_ctx {
};
#define AES_BLOCK_LEN 16
#define AES_NONCE_LEN 13
static void ccmp_detach(struct ieee80211_key *);
static int ccmp_setkey(struct ieee80211_key *);
const struct ieee80211_cipher ccmp = {
"AES-CCM",
0,
};
/* ARGSUSED */
static void *
{
return (NULL);
return (ctx);
}
static void
ccmp_detach(struct ieee80211_key *k)
{
}
static int
ccmp_setkey(struct ieee80211_key *k)
{
return (0);
return (1);
}
/*
* Add privacy headers appropriate for the specified key.
*/
static int
{
int hdrlen;
/*
* Copy down 802.11 header and add the IV, KeyID, and ExtIV.
*/
k->wk_keytsc++; /* wrap at 48 bits */
/*
* Finally, do software encrypt if neeed.
*/
if ((k->wk_flags & IEEE80211_KEY_SWCRYPT) &&
return (0);
return (1);
}
/*
* Validate and strip privacy headers (and trailer) for a
* received frame. The specified key should be correct but
* is also verified.
*/
static int
{
/*
* Header should have extended IV and sequence number;
* verify the former and validate the latter.
*/
/*
* No extended IV; discard frame.
*/
return (0);
}
/*
* Replay violation.
*/
return (0);
}
/*
* Check if the device handled the decrypt in hardware.
* If so we just strip the header; otherwise we need to
* handle the decrypt in software. Note that for the
* latter we leave the header in place for use in the
* decryption work.
*/
if ((k->wk_flags & IEEE80211_KEY_SWCRYPT) &&
return (0);
/*
* Copy up 802.11 header and strip crypto bits.
*/
/*
* Ok to update rsc now.
*/
return (1);
}
/*
* Add MIC to the frame as needed.
*/
/* ARGSUSED */
static int
{
return (1);
}
/*
* Verify and strip MIC from the frame.
*/
/* ARGSUSED */
static int
{
return (1);
}
static int
{
int rv;
/* keys are measured in bits, not bytes, so multiply by 8 */
#else
#endif
if (rv != CRYPTO_SUCCESS)
return (rv);
}
static int
{
int rv;
/* keys are measured in bits, not bytes, so multiply by 8 */
#else
#endif
if (rv != CRYPTO_SUCCESS)
return (rv);
}
/*
* For the avoidance of doubt, except that if any license choice other
* than GPL or LGPL is available it will apply instead, Sun elects to
* use only the General Public License version 2 (GPLv2) at this time
* for any software where a choice of GPL license versions is made
* available with the language indicating that GPLv2 or any later
* version may be used, or where a choice of which version of the GPL
* is applied is otherwise unspecified.
*/
/*
* Host AP crypt: host-based CCMP encryption implementation for Host AP driver
*
* Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi>
*
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. See README and COPYING for
* more details.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*/
static void
{
/*
* CCM Initial Block:
* Flag (Include authentication header, M=3 (8-octet MIC),
* L=1 (2-octet Dlen))
* Nonce: 0x00 | A2 | PN
* Dlen
*/
b0[0] = 0x59;
/* b0[1] set below */
/*
* AAD:
* FC with bits 4..6 and 11..13 masked to zero; 14 is always one
* A1 | A2 | A3
* SC with bits 4..15 (seq#) masked to zero
* A4 (if present)
* QC (if present)
*/
aad[0] = 0; /* AAD length >> 8 */
/* aad[1] set below */
/* we know 3 addresses are contiguous */
/*
* Construct variable-length portion of AAD based
* We always zero-pad to 32 bytes before running it
* through the cipher.
*
* We also fill in the priority bits of the CCM
* initial block as we know whether or not we have
* a QOS frame.
*/
if (IEEE80211_QOS_HAS_SEQ(wh)) {
struct ieee80211_qosframe *qwh =
(struct ieee80211_qosframe *)wh;
aad[25] = 0;
} else {
b0[1] = 0;
}
}
static int
{
struct ieee80211_frame *wh;
}
static int
{
struct ieee80211_frame *wh;
}