]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
dtls: Add types and operations required for the DTLS epoch and sequence.
authorJonathan Bastien-Filiatrault <joe@x2a.org>
Tue, 28 Jul 2009 01:47:55 +0000 (21:47 -0400)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 17 Feb 2011 21:30:07 +0000 (22:30 +0100)
Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
lib/gnutls_int.h
lib/gnutls_num.c
lib/gnutls_num.h
lib/gnutls_record.c

index 81563215f584f2bf4e5e163f969a48d5f43e5d87..2409776e8fc0ba3207e3101f591bfb538c5e858e 100644 (file)
@@ -57,6 +57,11 @@ typedef struct
   unsigned char i[8];
 } uint64;
 
+typedef struct
+{
+  unsigned char i[6];
+} uint48;
+
 #include <gnutls/gnutls.h>
 
 /*
index 2c75541ca64bb2686a5cee61956715efc1d1f216..eeadd3e280f810da83741ee08d58d3a128b38be6 100644 (file)
@@ -62,6 +62,35 @@ _gnutls_uint64pp (uint64 * x)
   return 0;
 }
 
+/* This function will add one to uint48 x.
+ * Returns 0 on success, or -1 if the uint48 max limit
+ * has been reached.
+ */
+int
+_gnutls_uint48pp (uint48 * x)
+{
+  register int i, y = 0;
+
+  for (i = 5; i >= 0; i--)
+    {
+      y = 0;
+      if (x->i[i] == 0xff)
+       {
+         x->i[i] = 0;
+         y = 1;
+       }
+      else
+       x->i[i]++;
+
+      if (y == 0)
+       break;
+    }
+  if (y != 0)
+    return -1;                 /* over 48 bits! meh... */
+
+  return 0;
+}
+
 uint32_t
 _gnutls_uint24touint32 (uint24 num)
 {
index 437539ec1710a229cb3bb51d2bfe6daa1272b8cd..2157804c57d424c789af7c827846f03be4683368 100644 (file)
@@ -43,7 +43,8 @@ void _gnutls_write_uint16 (uint16_t num, opaque * data);
 uint32_t _gnutls_uint64touint32 (const uint64 *);
 
 int _gnutls_uint64pp (uint64 *);
-#define _gnutls_uint64zero(x) x.i[0] = x.i[1] = x.i[2] = x.i[3] = x.i[4] = x.i[5] = x.i[6] = x.i[7] = 0
-#define UINT64DATA(x) ((x).i)
+int _gnutls_uint48pp (uint48 *);
+# define _gnutls_uint64zero(x) x.i[0] = x.i[1] = x.i[2] = x.i[3] = x.i[4] = x.i[5] = x.i[6] = x.i[7] = 0
+# define UINT64DATA(x) ((x).i)
 
 #endif /* GNUTLS_NUM_H */
index 66f85ca2a5b31c019cbe51339ea0f8c6dc963659..9c11d6d4fbe8a1ddb7898bea78d2f63f429f2150 100644 (file)
@@ -319,6 +319,38 @@ copy_record_version (gnutls_session_t session,
     }
 }
 
+/* Increments the sequence value
+ */
+inline static int
+sequence_increment (gnutls_session_t session,
+                   uint64 * value)
+{
+  if (_gnutls_is_dtls(session))
+    {
+      return _gnutls_uint48pp((uint48*)&value->i[2]);
+    }
+  else
+    {
+      return _gnutls_uint64pp(value);
+    }
+}
+
+/* Read epoch and sequence from a DTLS packet */
+inline static void
+sequence_read (uint64 * sequence,
+              opaque * data)
+{
+  memcpy(sequence->i, data, 8);
+}
+
+/* Write epoch and sequence to a DTLS packet */
+inline static void
+sequence_write (uint64 * sequence,
+               opaque * data)
+{
+  memcpy(data, sequence->i, 8);
+}
+
 /* This function behaves exactly like write(). The only difference is
  * that it accepts, the gnutls_session_t and the content_type_t of data to
  * send (if called by the user the Content is specific)