• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ink_auth_api.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   PE/TE authentication definitions
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #ifndef __INK_AUTH_API_H_INCLUDDED__
00025 #define __INK_AUTH_API_H_INCLUDDED__
00026 
00027 #include <sys/types.h>
00028 #include <string.h>
00029 
00030 #include "ink_defs.h"
00031 
00032 typedef union
00033 {
00034   uint64_t u64[2];
00035   uint32_t u32[4];
00036   uint16_t u16[8];
00037   uint8_t u8[16];
00038 } INK_AUTH_TOKEN;
00039 
00040 class INK_AUTH_SEED
00041 {
00042 public:
00043   const void *data() const
00044   {
00045     return m_data;
00046   }
00047   unsigned length() const
00048   {
00049     return m_length;
00050   }
00051 
00052   inline INK_AUTH_SEED(const void *x, unsigned ln)
00053   {
00054     init(x, ln);
00055   }
00056 
00057   inline INK_AUTH_SEED(const uint8_t & x)
00058   {
00059     init((const void *) &x, sizeof(x));
00060   }
00061   inline INK_AUTH_SEED(const uint16_t & x)
00062   {
00063     init((const void *) &x, sizeof(x));
00064   }
00065   inline INK_AUTH_SEED(const uint32_t & x)
00066   {
00067     init((const void *) &x, sizeof(x));
00068   }
00069   inline INK_AUTH_SEED(const uint64_t & x)
00070   {
00071     init((const void *) &x, sizeof(x));
00072   }
00073   inline INK_AUTH_SEED(const int8_t & x)
00074   {
00075     init((const void *) &x, sizeof(x));
00076   }
00077   inline INK_AUTH_SEED(const int16_t & x)
00078   {
00079     init((const void *) &x, sizeof(x));
00080   }
00081   inline INK_AUTH_SEED(const int32_t & x)
00082   {
00083     init((const void *) &x, sizeof(x));
00084   }
00085   inline INK_AUTH_SEED(const int64_t & x)
00086   {
00087     init((const void *) &x, sizeof(x));
00088   }
00089 
00090   inline INK_AUTH_SEED(const INK_AUTH_TOKEN & x)
00091   {
00092     init((const void *) &(x.u8[0]), sizeof(x.u8));
00093   }
00094 
00095   inline INK_AUTH_SEED(const char *str)
00096   {
00097     init((const void *) str, strlen((const char *) str));
00098   }
00099 
00100   inline INK_AUTH_SEED(const char *str, unsigned ln)
00101   {
00102     init((const void *) str, ln);
00103   }
00104 
00105   inline INK_AUTH_SEED(const unsigned char *str)
00106   {
00107     init((const void *) str, strlen((const char *) str));
00108   }
00109 
00110   inline INK_AUTH_SEED(const unsigned char *str, unsigned ln)
00111   {
00112     init((const void *) str, ln);
00113   }
00114 
00115 protected:
00116 
00117   void init(const void *d, unsigned l)
00118   {
00119     m_data = d;
00120     m_length = l;
00121   }
00122 
00123   const void *m_data;
00124   unsigned m_length;
00125 };
00126 
00127 
00128 void ink_make_token(INK_AUTH_TOKEN * tok, const INK_AUTH_TOKEN & mask, const INK_AUTH_SEED * const *seeds, int slen);
00129 
00130 uint32_t ink_make_token32(uint32_t mask, const INK_AUTH_SEED * const *seeds, int slen);
00131 uint64_t ink_make_token64(uint64_t mask, const INK_AUTH_SEED * const *seeds, int slen);
00132 
00133 uint32_t ink_get_rand();
00134 
00135 #define INK_TOKENS_EQUAL(m,t1,t2) ((((t1)^(t2))&(~(m))) == 0)
00136 
00137 //
00138 // Helper functions - wiil create INK_AUTH_SEEDs from base types on fly
00139 //
00140 inline uint32_t
00141 ink_make_token32(uint32_t mask, const INK_AUTH_SEED & s1)
00142 {
00143   const INK_AUTH_SEED *s[] = { &s1 };
00144   return ink_make_token32(mask, s, sizeof(s) / sizeof(*s));
00145 }
00146 
00147 inline uint32_t
00148 ink_make_token32(uint32_t mask, const INK_AUTH_SEED & s1, const INK_AUTH_SEED & s2)
00149 {
00150   const INK_AUTH_SEED *s[] = { &s1, &s2 };
00151   return ink_make_token32(mask, s, sizeof(s) / sizeof(*s));
00152 }
00153 
00154 inline uint32_t
00155 ink_make_token32(uint32_t mask, const INK_AUTH_SEED & s1, const INK_AUTH_SEED & s2, const INK_AUTH_SEED & s3)
00156 {
00157   const INK_AUTH_SEED *s[] = { &s1, &s2, &s3 };
00158   return ink_make_token32(mask, s, sizeof(s) / sizeof(*s));
00159 }
00160 
00161 inline uint32_t
00162 ink_make_token32(uint32_t mask,
00163                  const INK_AUTH_SEED & s1, const INK_AUTH_SEED & s2, const INK_AUTH_SEED & s3, const INK_AUTH_SEED & s4)
00164 {
00165   const INK_AUTH_SEED *s[] = { &s1, &s2, &s3, &s4 };
00166   return ink_make_token32(mask, s, sizeof(s) / sizeof(*s));
00167 }
00168 
00169 inline uint32_t
00170 ink_make_token32(uint32_t mask,
00171                  const INK_AUTH_SEED & s1,
00172                  const INK_AUTH_SEED & s2, const INK_AUTH_SEED & s3, const INK_AUTH_SEED & s4, const INK_AUTH_SEED & s5)
00173 {
00174   const INK_AUTH_SEED *s[] = { &s1, &s2, &s3, &s4, &s5 };
00175   return ink_make_token32(mask, s, sizeof(s) / sizeof(*s));
00176 }
00177 
00178 inline uint64_t
00179 ink_make_token64(uint64_t mask, const INK_AUTH_SEED & s1)
00180 {
00181   const INK_AUTH_SEED *s[] = { &s1 };
00182   return ink_make_token64(mask, s, sizeof(s) / sizeof(*s));
00183 }
00184 
00185 inline uint64_t
00186 ink_make_token64(uint64_t mask, const INK_AUTH_SEED & s1, const INK_AUTH_SEED & s2)
00187 {
00188   const INK_AUTH_SEED *s[] = { &s1, &s2 };
00189   return ink_make_token64(mask, s, sizeof(s) / sizeof(*s));
00190 }
00191 
00192 inline uint64_t
00193 ink_make_token64(uint64_t mask, const INK_AUTH_SEED & s1, const INK_AUTH_SEED & s2, const INK_AUTH_SEED & s3)
00194 {
00195   const INK_AUTH_SEED *s[] = { &s1, &s2, &s3 };
00196   return ink_make_token64(mask, s, sizeof(s) / sizeof(*s));
00197 }
00198 
00199 inline uint64_t
00200 ink_make_token64(uint64_t mask,
00201                  const INK_AUTH_SEED & s1, const INK_AUTH_SEED & s2, const INK_AUTH_SEED & s3, const INK_AUTH_SEED & s4)
00202 {
00203   const INK_AUTH_SEED *s[] = { &s1, &s2, &s3, &s4 };
00204   return ink_make_token64(mask, s, sizeof(s) / sizeof(*s));
00205 }
00206 
00207 inline uint64_t
00208 ink_make_token64(uint64_t mask,
00209                  const INK_AUTH_SEED & s1,
00210                  const INK_AUTH_SEED & s2, const INK_AUTH_SEED & s3, const INK_AUTH_SEED & s4, const INK_AUTH_SEED & s5)
00211 {
00212   const INK_AUTH_SEED *s[] = { &s1, &s2, &s3, &s4, &s5 };
00213   return ink_make_token64(mask, s, sizeof(s) / sizeof(*s));
00214 }
00215 
00216 inline int64_t
00217 INK_AUTH_MAKE_INT_64(uint32_t h, uint32_t l)
00218 {
00219   return int64_t((((uint64_t) h) << 32) + (uint32_t) l);
00220 }
00221 
00222 inline int64_t
00223 INK_AUTH_MAKE_INT_64(uint32_t u)
00224 {
00225   return INK_AUTH_MAKE_INT_64(u, u);
00226 }
00227 
00228 #endif // #ifndef __INK_AUTH_API_H_INCLUDDED__

Generated by  doxygen 1.7.1